parent
2b49211d9f
commit
e75e96760c
@ -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