package com.model.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.model.bean.UserInfo;
public class AddUserDaoImp implements AddUserDao {
private Connection conn;
public AddUserDaoImp(Connection conn) {
this.conn = conn;
}
@Override
public boolean validateUsername(UserInfo user) throws SQLException {
String sql="select * from userinfo1 where username=?";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1, user.getUsername());
ResultSet rs=ps.executeQuery();
boolean flag;
if(rs.next()){
flag=true;
}else{
flag=false;
}
ps.close();
return flag;
}
@Override
public void saveUser(UserInfo user) throws SQLException {
String sql="insert into userinfo1(username,password,newpassword,name,email,phone,role,skin) values(?,?,?,?,?,?,?,?)";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1, user.getUsername());
ps.setString(2, user.getPassword());
ps.setString(3, user.getNewpassword());
ps.setString(4, user.getName());
ps.setString(5, user.getEmail());
ps.setString(6, user.getPhone());
ps.setString(7, user.getRole());
ps.setString(8, user.getSkin());
ps.executeUpdate();
ps.close();
}
}