Compare commits
2 Commits
main
...
javaDaoimp
Author | SHA1 | Date |
---|---|---|
|
55fb341b78 | 1 year ago |
|
e75e96760c | 1 year ago |
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,204 @@
|
||||
package JavaDaoimple;
|
||||
|
||||
import JavaBean.zhanjicxs;
|
||||
import JavaDao.zhanjiDaocxs;
|
||||
import wuziqiyem.JDBCUtil;
|
||||
import wuziqiyem.huoqu;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class zhanjicxsimple implements zhanjiDaocxs {
|
||||
@Override
|
||||
public List<zhanjicxs> findAll() {
|
||||
List<zhanjicxs> zhanjicxs = new ArrayList<>();
|
||||
try{
|
||||
Connection connection= JDBCUtil.getConnection();
|
||||
String sql = "select * from zhanji";
|
||||
Statement sts = connection.createStatement();
|
||||
ResultSet rs = sts.executeQuery(sql);
|
||||
while (rs.next()) {
|
||||
zhanjicxs zhanji =new zhanjicxs();
|
||||
zhanji.setId(rs.getInt("id"));
|
||||
zhanji.setUserid(rs.getString("userid"));
|
||||
zhanji.setShenglv(rs.getString("shenglv"));
|
||||
zhanji.setStiuation(rs.getString("station"));
|
||||
zhanji.setTime(rs.getInt("time"));
|
||||
zhanji.setSuccess(rs.getInt("success"));
|
||||
zhanji.sethe(rs.getInt("he"));
|
||||
zhanjicxs.add(zhanji);
|
||||
}
|
||||
rs.close();
|
||||
sts.close();
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return zhanjicxs;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public zhanjicxs findById() {
|
||||
zhanjicxs zhanji = new zhanjicxs();
|
||||
try {
|
||||
Connection connection= JDBCUtil.getConnection();
|
||||
String sql="SELECT * FROM zhanji WHERE id = (SELECT MAX(id) FROM zhanji)";
|
||||
PreparedStatement pstm=connection.prepareStatement(sql);
|
||||
ResultSet rs=pstm.executeQuery();
|
||||
|
||||
if(rs.next()){
|
||||
zhanji.setId(rs.getInt("id"));
|
||||
zhanji.setUserid(rs.getString("userid"));
|
||||
zhanji.setShenglv(rs.getString("shenglv"));
|
||||
zhanji.setStiuation(rs.getString("station"));
|
||||
zhanji.setTime(rs.getInt("time"));
|
||||
}else{
|
||||
System.out.println("当前用户不存在");
|
||||
rs.close();
|
||||
pstm.close();
|
||||
connection.close();
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return zhanji;
|
||||
}
|
||||
|
||||
@Override
|
||||
public zhanjicxs findById(int id) {
|
||||
zhanjicxs zhanji = new zhanjicxs();
|
||||
try {
|
||||
Connection connection= JDBCUtil.getConnection();
|
||||
String sql="select * from zhanji where id=?";
|
||||
PreparedStatement pstm=connection.prepareStatement(sql);
|
||||
pstm.setInt(1,zhanji.getId());
|
||||
ResultSet rs=pstm.executeQuery();
|
||||
|
||||
if(rs.next()){
|
||||
zhanji.setId(rs.getInt("id"));
|
||||
zhanji.setUserid(rs.getString("userid"));
|
||||
zhanji.setShenglv(rs.getString("shenglv"));
|
||||
zhanji.setStiuation(rs.getString("station"));
|
||||
zhanji.setTime(rs.getInt("time"));
|
||||
}else{
|
||||
System.out.println("当前用户不存在");
|
||||
rs.close();
|
||||
pstm.close();
|
||||
connection.close();
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return zhanji;
|
||||
}
|
||||
|
||||
@Override
|
||||
public zhanjicxs findById1() {
|
||||
zhanjicxs zhanji = new zhanjicxs();
|
||||
try {
|
||||
huoqu huoqu=new huoqu();
|
||||
String id;
|
||||
id=huoqu.getUserid();
|
||||
Connection connection= JDBCUtil.getConnection();
|
||||
|
||||
|
||||
String sql="SELECT * FROM zhanji WHERE success = (SELECT MAX(success) FROM zhanji)";
|
||||
PreparedStatement pstm=connection.prepareStatement(sql);
|
||||
ResultSet rs=pstm.executeQuery();
|
||||
|
||||
if(rs.next()){
|
||||
zhanji.setId(rs.getInt("id"));
|
||||
zhanji.setUserid(rs.getString("userid"));zhanji.setShenglv(rs.getString("shenglv"));
|
||||
zhanji.setStiuation(rs.getString("station"));
|
||||
zhanji.setTime(rs.getInt("time"));
|
||||
zhanji.setSuccess(rs.getInt("success"));
|
||||
zhanji.sethe(rs.getInt("he"));
|
||||
}else{
|
||||
System.out.println("当前用户不存在");
|
||||
rs.close();
|
||||
pstm.close();
|
||||
connection.close();
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return zhanji;
|
||||
}
|
||||
@Override
|
||||
public zhanjicxs findById2() {
|
||||
zhanjicxs zhanji = new zhanjicxs();
|
||||
try {
|
||||
huoqu huoqu=new huoqu();
|
||||
String id3;
|
||||
id3=huoqu.getUserid();
|
||||
Connection connection= JDBCUtil.getConnection();
|
||||
|
||||
String sql="SELECT * FROM zhanji WHERE success = (SELECT MAX(success) FROM zhanji),userid=id";
|
||||
PreparedStatement pstm=connection.prepareStatement(sql);
|
||||
ResultSet rs=pstm.executeQuery();
|
||||
|
||||
if(rs.next()){
|
||||
zhanji.setId(rs.getInt("id"));
|
||||
zhanji.setUserid(rs.getString("userid"));zhanji.setShenglv(rs.getString("shenglv"));
|
||||
zhanji.setStiuation(rs.getString("station"));
|
||||
zhanji.setTime(rs.getInt("time"));
|
||||
zhanji.setSuccess(rs.getInt("success"));
|
||||
zhanji.sethe(rs.getInt("he"));
|
||||
}else{
|
||||
System.out.println("当前用户不存在");
|
||||
rs.close();
|
||||
pstm.close();
|
||||
connection.close();
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return zhanji;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(zhanjicxs zhanjicxs) {
|
||||
int num=0;
|
||||
try {
|
||||
Connection connection=JDBCUtil.getConnection();
|
||||
String sql="insert into zhanji values(?,?,?,?,?,?,?)";
|
||||
PreparedStatement pstm=connection.prepareStatement(sql);
|
||||
pstm.setInt(1, zhanjicxs.getId());
|
||||
pstm.setString(2, zhanjicxs.getUserid());
|
||||
pstm.setString(3, zhanjicxs.getShenglv());
|
||||
pstm.setString(4, zhanjicxs.getStiuation());
|
||||
pstm.setInt(5, zhanjicxs.getTime());
|
||||
pstm.setInt(6, zhanjicxs.getSuccess());
|
||||
pstm.setInt(7, zhanjicxs.gethe());
|
||||
pstm.executeUpdate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in new issue