|
在jsp中用bean和servlet联合实现用户注册、登录(2) { return this.sql_DBName; }
public boolean setUser(String user) { this.user = user; return true; }
public String getUser() { return this.user; }
public boolean setPwd(String pwd) { this.pwd = pwd; return true; }
public String getPwd() { return this.pwd; }
public DBConn() { try{ Class.forName(sql_driver);//加载数据库驱动程序 this.conn = DriverManager.getConnection(sql_url + "/" + sql_DBName + "?user=" + user + "&passWord=" + pwd + "&useUnicode=true&characterEncoding=gb2312"); this.stmt = this.conn.createStatement(); }catch(Exception e){ System.out.println(e.toString()); } }
//执行查询操作 public ResultSet executeQuery(String strSql) { try{ this.rs = stmt.executeQuery(strSql); return this.rs; }catch(SQLException e){ System.out.println(e.toString()); return null; }catch(NullPointerException e){ System.out.println(e.toString()); return null; } }
//执行数据的插入、删除、修改操作 public boolean execute(String strSql) { try{ if(this.stmt.executeUpdate(strSql) == 0) return false; else return true; }catch(SQLException e){ System.out.println(e.toString()); return false;
|