?? userdao.java
字號:
package com.yy.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.yy.bean.UserBean;
public class UserDao extends DButils{
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;
String sql;
public boolean addUser(UserBean user){
boolean bool=false;
try {
con=this.getDataSource().getConnection();
sql="insert into userInfo values (?,?,?)";
ps=con.prepareStatement(sql);
ps.setString(1,user.getUserName());
ps.setString(2,user.getPassWord());
ps.setString(3,user.getEmail());
int num=ps.executeUpdate();
if(num>0){
bool=true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.closePs();
this.closeCon();
}
return bool;
}
public boolean getUser(UserBean bean){
boolean bool=false;
try {
con=this.getDataSource().getConnection();
sql="select * from userInfo where userName=? and passWord=?";
ps=con.prepareStatement(sql);
ps.setString(1, bean.getUserName());
ps.setString(2,bean.getPassWord());
rs=ps.executeQuery();
while(rs.next()){
bool=true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.closeRs();
this.closePs();
this.closeCon();
}
return bool;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -