parent
e75e96760c
commit
55fb341b78
@ -0,0 +1,130 @@
|
||||
package JavaDaoimple;
|
||||
|
||||
|
||||
import JavaBean.Accountcxs;
|
||||
import JavaDao.AccountDaocxs;
|
||||
import wuziqiyem.JDBCUtil;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Accountcxsimple implements AccountDaocxs {
|
||||
public ArrayList<Accountcxs> findAll() {
|
||||
try{
|
||||
Connection connection= JDBCUtil.getConnection();
|
||||
String sql = "select * from account";
|
||||
Statement sts = connection.createStatement();
|
||||
ResultSet rs = sts.executeQuery(sql);
|
||||
while (rs.next()) {
|
||||
Accountcxs ac = new Accountcxs();
|
||||
ac.setCountrycxs(rs.getString("country"));
|
||||
ac.setEmallcxs(rs.getString("email"));
|
||||
ac.setNamecxs(rs.getString("Name"));
|
||||
ac.setPasswordcxs(rs.getString("password"));
|
||||
ac.setPhonecxs(rs.getString("phone"));
|
||||
ac.setUseridcxs(rs.getString("userid"));
|
||||
}
|
||||
rs.close();
|
||||
sts.close();
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
@Override
|
||||
public Accountcxs findByID (String userid) {
|
||||
Accountcxs ac = new Accountcxs();
|
||||
try {
|
||||
Connection connection= JDBCUtil.getConnection();
|
||||
String sql="select * from account where userid=?";
|
||||
PreparedStatement pstm=connection.prepareStatement(sql);
|
||||
pstm.setString(1,userid);
|
||||
ResultSet rs=pstm.executeQuery();
|
||||
|
||||
if(rs.next()){
|
||||
ac.setCountrycxs(rs.getString("country"));
|
||||
ac.setEmallcxs(rs.getString("email"));
|
||||
ac.setNamecxs(rs.getString("Name"));
|
||||
ac.setPasswordcxs(rs.getString("password"));
|
||||
ac.setPhonecxs(rs.getString("phone"));
|
||||
ac.setUseridcxs(rs.getString("userid"));
|
||||
System.out.println(ac.getUseridcxs()+" "+ac.getCountrycxs()+" "+ac.getEmallcxs()+" "+ac.getNamecxs()+" "+ac.getPasswordcxs()+" "+ac.getPhonecxs());
|
||||
}else{
|
||||
System.out.println("当前用户不存在");
|
||||
rs.close();
|
||||
pstm.close();
|
||||
connection.close();
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return ac;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int mod(Accountcxs accountcxs) {
|
||||
try {
|
||||
Connection connection= JDBCUtil.getConnection();
|
||||
String sql="update account set addr = ? , city=?,country=?,email=?,name=?,password=?,phone=?where userid=?";
|
||||
PreparedStatement pstm=connection.prepareStatement(sql);
|
||||
// ResultSet rs=pstm.executeQuery();
|
||||
// while(rs.next()){
|
||||
pstm.setString(3,accountcxs.getCountrycxs());
|
||||
pstm.setString(4,accountcxs.getEmallcxs());
|
||||
pstm.setString(5,accountcxs.getNamecxs());
|
||||
pstm.setString(6,accountcxs.getPasswordcxs());
|
||||
pstm.setString(7,accountcxs.getPhonecxs());
|
||||
pstm.setString(8,accountcxs.getUseridcxs());
|
||||
pstm.executeUpdate();
|
||||
// }
|
||||
// System.out.println(accountcxs.getUseridcxs()+" "+accountcxs.getAddrcxs()+" "+accountcxs.getCitycxs()+" "+accountcxs.getCountrycxs()+" "+accountcxs.getEmallcxs()+" "+accountcxs.getNamecxs()+" "+accountcxs.getPasswordcxs()+" "+accountcxs.getPhonecxs());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delect(String userid) {
|
||||
try {
|
||||
Connection connection= JDBCUtil.getConnection();
|
||||
String sql="delete from account where userid=?";
|
||||
PreparedStatement pstm=connection.prepareStatement(sql);
|
||||
pstm.setString(1,userid);
|
||||
pstm.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(Accountcxs accountcxs) {
|
||||
int num=0;
|
||||
try {
|
||||
Connection connection= JDBCUtil.getConnection();
|
||||
String sql="insert into account values(?,?,?,?,?,?)";
|
||||
PreparedStatement pstm=connection.prepareStatement(sql);
|
||||
pstm.setString(1, accountcxs.getUseridcxs());
|
||||
pstm.setString(2, accountcxs.getPasswordcxs());
|
||||
pstm.setString(3, accountcxs.getEmallcxs());
|
||||
pstm.setString(4, accountcxs.getNamecxs());
|
||||
pstm.setString(5, accountcxs.getCountrycxs());
|
||||
pstm.setString(6, accountcxs.getPhonecxs());
|
||||
pstm.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue