try{
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
System.out.println(sql);
rs=stmt.executeQuery(sql);
while (rs.next())
{
String [] result=new String[2];
result[0]=rs.getString("cdname");
result[1]=rs.getString("num");
al.add(result);
}
return al;
} catch (Exception e){
System.out.println(e.getMessage());
return null;
}
}
}
op_user.java:
package cdshop.run;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @Singer not attributable
* @version 1.0
*/
import java.sql.*;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import cdshop.util.*;
import cdshop.cd.*;
public class op_user extends DataBase{
private user user = new user(); //新的用户对象
private javax.servlet.http.HttpServletRequest request; //建立页面请求
private Vector userlist; //显示用户列表向量数组
private int page = 1; //显示的页码
private int pageSize=8; //每页显示的图书数
private int pageCount =0; //页面总数
private long recordCount =0; //查询的记录总数
private String message = ""; //出错信息提示
private String username = ""; //注册后返回的用户名
private long userid = 0; //注册后返回的用户ID
public op_user() {
}
//添加新用户
public boolean add(HttpServletRequest req) throws Exception {
if (getRequest(req)) {
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
sqlStr = "select * from shop_user where username = '" +
user.getUserName() +"'";
sqlStr = "insert into shop_user (username,password,Names,sex,"+
"Address,Phone,Post,Email,RegTime,RegIpaddress) values ('";
sqlStr = sqlStr + dataFormat.toSql(user.getUserName()) + "','";
sqlStr = sqlStr + dataFormat.toSql(user.getPassWord()) + "','";
sqlStr = sqlStr + dataFormat.toSql(user.getNames()) + "','";
sqlStr = sqlStr + dataFormat.toSql(user.getSex()) + "','";
sqlStr = sqlStr + dataFormat.toSql(user.getAddress()) + "','";
sqlStr = sqlStr + dataFormat.toSql(user.getPhone()) + "','";
sqlStr = sqlStr + dataFormat.toSql(user.getPost()) + "','";
sqlStr = sqlStr + dataFormat.toSql(user.getEmail()) + "',GETDATE(),'";
sqlStr = sqlStr + user.getRegIpAddress() + "')";
try{
stmt.executeUpdate(sqlStr);
sqlStr = "select max(id) from shop_user where username = '" +
user.getUserName()+ "'";
rs = stmt.executeQuery(sqlStr);
while (rs.next()){
userid = rs.getLong(1);
}
close();
return true;
}catch (Exception sqle){
System.out.print(sqle.getMessage());
return false;
}
} else{
return false;
}
}
//分析页面转递的参数
public boolean getRequest(javax.servlet.http.HttpServletRequest newrequest) {
boolean flag = false;
try {
request = newrequest;
String ID = request.getParameter("userid");
if (ID!=null ){
userid = 0;
try{
userid = Long.parseLong(ID);
user.setId(userid);
}catch (Exception e){
message = message + "你要修改的用户号出错!";
}
}
username = request.getParameter("username");
if (username==null || username.equals("")){
username = "";
message = message + "用户名为空!";
}
user.setUserName(getGbk(username));
String password = request.getParameter("passwd");
if (password==null || password.equals("")){
password = "";
message = message + "密码为空!";
}
String pwdconfirm = request.getParameter("passconfirm");
if (!password.equals(pwdconfirm)){
message = message + "确认密码不相同!";
}
user.setPassWord(getGbk(password));
String names = request.getParameter("names");;
if (names==null){
names = "";
}
user.setNames(getGbk(names));
String sex = request.getParameter("sex");
user.setSex(getGbk(sex));
String address = request.getParameter("address");
if (address == null){
address = "";
}
user.setAddress(getGbk(address));
String post = request.getParameter("post");
if (post == null){
post = "";
}
user.setPost(getGbk(post));
String phone = request.getParameter("phone");
if (phone== null){
phone = "";
}
user.setPhone(phone);
String email = request.getParameter("email");
if (email == null){
email = "";
<< 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] 下一页