1、} //获得指定商品信息 public static String[] getRowStock(String id) { String[] s=new String[6];1.DBUtil_SM.class自定义了各种对数据操作的静态方法,包括对各个数据库的增删改查,其中对于user表中的删除仅能由权限2以上的管理人员执行,代码如下(手工编写) package paim; import java.sql.*; import java.util.*; import jav
2、a.io.*;
public class DBUtil_SM
{
//获取用户信息
public static List
3、con.createStatement();
String sql="select id,name,age,sex,workuntil,tel,lvl,total from VIP_IM";
ResultSet rs=st.executeQuery(sql);
while(rs.next())
{
String[] s=new String[8];
for(int i=0;i 4、 }
rs.close();
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
return vl;
}
//获取库存信息
public static List 5、r");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
String sql="select id,name,price,count,vprice,type from stock order by type";
ResultSet rs=st.executeQuery(sql);
while(rs.next())
{
String[] s=new String[6];
6、 for(int i=0;i 7、tic void toInsertID(String[] s)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
String sql="insert into VIP_IM values('"+s[0]+"','"+s[1]+"','"+s[2]+"','"+s[3]+"','"+s 8、[4]+"','"+s[5]+"','"+s[6]+"','"+s[7]+"')";
st.executeUpdate(sql);
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
//删除用户信息
public static void toDelID(String id)
{
try
{
Class.forName("sun 9、jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
st.executeUpdate("delete from VIP_IM where id='"+id+"'");
st.executeUpdate("delete from user where id='"+id+"'");
st.close();
con.close();
10、}catch(Exception e)
{
e.printStackTrace();
}
}
//更新用户数据
public static void toUpdateID(String[] s)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatem 11、ent();
String sql="update VIP_IM set name='"+s[1]+"',age="+s[2]+",sex='"+s[3]+"',workuntil='"+s[4]+"',tel='"+s[5]+"',lvl='"+s[6]+"',total="+s[7]+" where id='"+s[0]+"'";
st.executeUpdate(sql);
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
//提 12、取一个用户信息
public static String[] getRowID(String id)
{
String[] s=new String[8];
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("se 13、lect id,name,age,sex,workuntil,tel,lvl,total from VIP_IM where id='"+id+"'");
if(rs.next())
{
for(int i=0;i 14、n s;
}
//删除库存信息
public static void toDelStock(String id)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
st.executeUpdate("delete from stock where id='"+id+" 15、'");
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
//添加库存信息
public static void toInsertStock(String[] s)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
16、 Statement st=con.createStatement();
String sql="insert into stock values('"+s[0]+"','"+s[1]+"','"+s[2]+"','"+s[3]+"','"+s[4]+"','"+s[5]+"')";
st.executeUpdate(sql);
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
//更新物品信息 17、
public static void toUpdateStock(String[] s)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
String sql="update stock set name='"+s[1]+"',p 18、rice="+s[2]+",count="+s[3]+",vprice="+s[4]+",type='"+s[5]+"' where id='"+s[0]+"'";
st.executeUpdate(sql);
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager 19、getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select id,name,price,count,vprice,type from stock where id='"+id+"'");
if(rs.next())
{
for(int i=0;i 20、lose();
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
return s;
}
//用户登录
public static int getUser(String[] k)
{
String[] s=new String[4];
int i=0;
try
{
Class.forNa 21、me("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select id,name,lit,psw from user where id='"+k[0]+"'");
if(rs.next())
{
for(int j=0;j 22、{
s[j]=rs.getString(j+1);
}
i=5;
}else
{
return i;
}
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(Exception e 23、)
{
e.printStackTrace();
}
return i;
}
//修改密码
public static void toUpdatePsw(String[] s)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
String 24、 sql="update user set psw='"+s[1]+"' where id='"+s[0]+"'";
st.executeUpdate(sql);
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
//获取积分列表
public static List 25、[]> sl=new ArrayList 26、Query(sql);
while(rs.next())
{
String[] s=new String[3];
for(int i=0;i 27、
}
//获取商品积分
public static int getTotalS(String id)
{
int t=0;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
S 28、tatement st=con.createStatement();
String sql="select total from total where id='"+id+"'";
ResultSet rs=st.executeQuery(sql);
if(rs.next())
{
t=rs.getInt(1);
}
rs.close();
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
ret 29、urn t;
}
//获取用户积分
public static int getTotalV(String id)
{
int t=0;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createState 30、ment();
String sql="select total from VIP_IM where id='"+id+"'";
ResultSet rs=st.executeQuery(sql);
if(rs.next())
{
t=rs.getInt(1);
}
rs.close();
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
return t;
}
//获取积分商品名称 31、
public static String getTotalName(String id)
{
String t="";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc: 32、odbc:dbsm","","");
Statement st=con.createStatement();
String sql="select name from total where id='"+id+"'";
ResultSet rs=st.executeQuery(sql);
if(rs.next())
{
t=rs.getString(1);
}
rs.close();
st.close();
con.close();
}catch(Exception e)
{
e.print 33、StackTrace();
}
return t;
}
//积分兑换表
public static void addList(String[] s)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con 34、createStatement();
String sql="insert into totallist(id,name,ltotal,tname,ttotal) values('"+s[0]+"','"+s[1]+"','"+s[2]+"','"+s[3]+"','"+s[4]+"')";
st.executeUpdate(sql);
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
//用户消费记录 35、
public static List 36、reateStatement();
String sql="select id,name,ltotal,tname,ttotal from totallist where id='"+id+"'";
ResultSet rs=st.executeQuery(sql);
while(rs.next())
{
String[] s=new String[5];
for(int i=0;i 37、s);
}
rs.close();
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
return sl;
}
//用户账户插入
public static void toInsertUser(String[] s)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDr 38、iver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
String sql="insert into user values('"+s[0]+"','"+s[1]+"','"+s[2]+"','"+s[3]+"')";
st.executeUpdate(sql);
st.close();
con.close();
}catch(Exception e)
{
e 39、printStackTrace();
}
}
//积分物品添加
public static void addTotal(String[] s)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStat 40、ement();
String sql="insert into total values('"+s[0]+"','"+s[1]+"','"+s[2]+"')";
st.executeUpdate(sql);
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
//更新积分物品信息 41、
public static void toUpdateTotal(String[] s)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
String sql="update total set name='"+s[1]+"',total='"+s[2]+"' 42、where id='"+s[0]+"'";
st.executeUpdate(sql);
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
//删除积分物品信息
public static void toDelTotal(String id)
{
try
{
Class.forName("sun.jdbc 43、odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
st.executeUpdate("delete from total where id='"+id+"'");
st.close();
con.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
//获取积 44、分列表
public static String[] getTotalListS(String id)
{
String[] s=new String[3];
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dbsm","","");
Statement st=con.createStatement();
45、
String sql="select id,name,total from total where id='"+id+"'";
ResultSet rs=st.executeQuery(sql);
while(rs.next())
{
for(int i=0;i 46、
{
e.printStackTrace();
}
return s;
}
}
2.SMServlet.class用于响应jsp请求根据情况调用DBUtil_SM中的方法,返回结果,代码如下(手工编写)
package paim;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class SMServlet extends HttpServlet
{
@Override
public void doGet(HttpServlet 47、Request request,HttpServletResponse response) throws IOException,ServletException
{
doPost(request,response);
}
@Override
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
String action=request.getParameter("action");
48、
if(action.equals("del_id"))//删除用户
{
String id=request.getParameter("id");
DBUtil_SM.toDelID(id);
request.getRequestDispatcher("/admin.jsp").include(request,response);
}
if(action.equals("add_id"))//添加用户
{
String[] s=new String[9];
if(request.getParameter("id" 49、)!=null) {
s[0]= new String(request.getParameter("id").getBytes("ISO8859_1"), "GB2312");}
if(request.getParameter("name")!=null) {
s[1] = new String(request.getParameter("name").getBytes("ISO8859_1"), "GB2312");}
if(request.getParameter("age")!=null) {
s[2] = new String(request.getParamet 50、er("age").getBytes("ISO8859_1"), "GB2312");}
if(request.getParameter("sex")!=null) {
s[3] = new String(request.getParameter("sex").getBytes("ISO8859_1"), "GB2312");}
if(request.getParameter("workuntil")!=null) {
s[4] = new String(request.getParameter("workuntil").getBytes("ISO8859_
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4009-655-100 投诉/维权电话:18658249818