public class UsersDAO {
private Connection con;
private PreparedStatement pt;
private ResultSet rs;
public boolean findUsers(String username){
boolean flag=false;
con=DatabaseDAO.getConnection();
try{
pt=con.prepareStatement("select*from users where username=?"); //获得PreparedStatement对象
pt.setString(1,username); //为参数赋值
rs=pt.executeQuery(); //执行查询语句,获取结果集
if (rs.next()){ //若果继续执行,表示用户名存在
flag=true;
}
}catch(SQLException e){ //捕获异常信息
e.printStackTrace();
}finally{
DatabaseDAO.closeRs(rs); //关闭相应资源
DatabaseDAO.closePt(pt); //关闭PreparedStatement
DatabaseDAO.closeCon(con); //关闭数据库连接
}
return flag;
}
public int save(Users users) {
// TODO Auto-generated method stub
int i=0;
con=DatabaseDAO.getConnection();
try{
pt=con.prepareStatement("inset into users(username,password,"+"name,nic,sex,age,email,phone,selfshow)values(?,?,?,?,?,?,?,?,?)");
pt.setString(1,users.getUsername());
pt.setString(2,users.getPassword());
pt.setString(3,users.getName());
pt.setString(4,users.getNic());
pt.setString(5,users.getSex());
pt.setInt(6,users.getAge());
pt.setString(7,users.getEmail());
pt.setString(8, users.getPhone());
pt.setString(9,users.getSelfshow());
i=pt.executeUpdate(); // 省略catch()和finally()方法
return i;
}
}
catch (Exception ex) { }
这样呢。在你的方法上加上throws Exception
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。