📄 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 + -