您好,欢迎访问三七文档
}//获得指定商品信息publicstaticString[]getRowStock(Stringid){String[]s=newString[6];1.DBUtil_SM.class自定义了各种对数据操作的静态方法,包括对各个数据库的增删改查,其中对于user表中的删除仅能由权限2以上的管理人员执行,代码如下(手工编写)packagepaim;importjava.sql.*;importjava.util.*;importjava.io.*;publicclassDBUtil_SM{//获取用户信息publicstaticListString[]getVIPList(){ArrayListString[]vl=newArrayListString[]();try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statementst=con.createStatement();Stringsql=selectid,name,age,sex,workuntil,tel,lvl,totalfromVIP_IM;ResultSetrs=st.executeQuery(sql);while(rs.next()){String[]s=newString[8];for(inti=0;is.length;i++){s[i]=rs.getString(i+1);}vl.add(s);}rs.close();st.close();con.close();}catch(Exceptione){e.printStackTrace();}returnvl;}//获取库存信息publicstaticListString[]getStockList(){ArrayListString[]sl=newArrayListString[]();try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statementst=con.createStatement();Stringsql=selectid,name,price,count,vprice,typefromstockorderbytype;ResultSetrs=st.executeQuery(sql);while(rs.next()){String[]s=newString[6];for(inti=0;is.length;i++){s[i]=rs.getString(i+1);}sl.add(s);}rs.close();st.close();con.close();}catch(Exceptione){e.printStackTrace();}returnsl;}//添加用户信息publicstaticvoidtoInsertID(String[]s){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statementst=con.createStatement();Stringsql=insertintoVIP_IMvalues('+s[0]+','+s[1]+','+s[2]+','+s[3]+','+s[4]+','+s[5]+','+s[6]+','+s[7]+');st.executeUpdate(sql);st.close();con.close();}catch(Exceptione){e.printStackTrace();}}//删除用户信息publicstaticvoidtoDelID(Stringid){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statementst=con.createStatement();st.executeUpdate(deletefromVIP_IMwhereid='+id+');st.executeUpdate(deletefromuserwhereid='+id+');st.close();con.close();}catch(Exceptione){e.printStackTrace();}}//更新用户数据publicstaticvoidtoUpdateID(String[]s){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statementst=con.createStatement();Stringsql=updateVIP_IMsetname='+s[1]+',age=+s[2]+,sex='+s[3]+',workuntil='+s[4]+',tel='+s[5]+',lvl='+s[6]+',total=+s[7]+whereid='+s[0]+';st.executeUpdate(sql);st.close();con.close();}catch(Exceptione){e.printStackTrace();}}//提取一个用户信息publicstaticString[]getRowID(Stringid){String[]s=newString[8];try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statementst=con.createStatement();ResultSetrs=st.executeQuery(selectid,name,age,sex,workuntil,tel,lvl,totalfromVIP_IMwhereid='+id+');if(rs.next()){for(inti=0;is.length;i++){s[i]=rs.getString(i+1);}}rs.close();st.close();con.close();}catch(Exceptione){e.printStackTrace();}returns;}//删除库存信息publicstaticvoidtoDelStock(Stringid){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statementst=con.createStatement();st.executeUpdate(deletefromstockwhereid='+id+');st.close();con.close();}catch(Exceptione){e.printStackTrace();}}//添加库存信息publicstaticvoidtoInsertStock(String[]s){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statementst=con.createStatement();Stringsql=insertintostockvalues('+s[0]+','+s[1]+','+s[2]+','+s[3]+','+s[4]+','+s[5]+');st.executeUpdate(sql);st.close();con.close();}catch(Exceptione){e.printStackTrace();}}//更新物品信息publicstaticvoidtoUpdateStock(String[]s){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statementst=con.createStatement();Stringsql=updatestocksetname='+s[1]+',price=+s[2]+,count=+s[3]+,vprice=+s[4]+,type='+s[5]+'whereid='+s[0]+';st.executeUpdate(sql);st.close();con.close();}catch(Exceptione){e.printStackTrace();}try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statementst=con.createStatement();ResultSetrs=st.executeQuery(selectid,name,price,count,vprice,typefromstockwhereid='+id+');if(rs.next()){for(inti=0;is.length;i++){s[i]=rs.getString(i+1);}}rs.close();st.close();con.close();}catch(Exceptione){e.printStackTrace();}returns;}//用户登录publicstaticintgetUser(String[]k){String[]s=newString[4];inti=0;try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statementst=con.createStatement();ResultSetrs=st.executeQuery(selectid,name,lit,pswfromuserwhereid='+k[0]+');if(rs.next()){for(intj=0;js.length;j++){s[j]=rs.getString(j+1);}i=5;}else{returni;}if(k[1].equals(s[3])){if(s[2].equals(1)){i=1;}else{i=2;}}else{i=3;}rs.close();st.close();con.close();}catch(Exceptione){e.printStackTrace();}returni;}//修改密码publicstaticvoidtoUpdatePsw(String[]s){try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectioncon=DriverManager.getConnection(jdbc:odbc:dbsm,,);Statemen
本文标题:超市系统的源代码
链接地址:https://www.777doc.com/doc-1410097 .html