📄 fwxxdao.java
字号:
package com.wepull.zf.dao.jdbcImpl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.wepull.zf.dao.IFWXXDAO;
import com.wepull.zf.entity.FWLX;
import com.wepull.zf.entity.FWXX;
public class FWXXDAO implements IFWXXDAO {
private Connection con;
public FWXXDAO(Connection con) {
super();
this.con = con;
}
public boolean del(int id) {
int flag=0;
try {
PreparedStatement ps=con.prepareStatement("delete from TBL_FWXX where fwid=?");
ps.setInt(1, id);
flag=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag>0;
}
public boolean edit(FWXX fwxx) {
int flag=0;
try {
PreparedStatement ps=con.prepareStatement("update TBL_FWXX set title=?,zj=?,uid=?,jdid=?,fwxx=?,shi=?,ting=?,telephone=?,lxr=?,lxid=?,date=? where fwid=?");
int index=0;
ps.setString(++index, fwxx.getTitle());
ps.setDouble(++index,fwxx.getZj());
ps.setInt(++index,fwxx.getUid());
ps.setInt(++index,fwxx.getJdid());
ps.setString(++index, fwxx.getFwxx());
ps.setInt(++index, fwxx.getShi());
ps.setInt(++index, fwxx.getTing());
ps.setString(++index, fwxx.getTelephone());
ps.setString(++index, fwxx.getLxr());
ps.setInt(++index, fwxx.getLxid());
ps.setString(++index, fwxx.getDate());
ps.setInt(++index, fwxx.getFwid());
flag=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag>0;
}
public List<FWXX> findAll(int page, int pageSize) {List< FWXX> houses=new ArrayList<FWXX>();
try {
PreparedStatement ps=con.prepareStatement("select * from tbl_fwxx",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
//rs可以看做一个游标指针
ResultSet rs=ps.executeQuery();
//定位器
int position=(page-1)*pageSize;
if(position>0){
rs.absolute(position);
}
//计数器
int count=0;
while(rs.next()&&count<pageSize){
FWXX house=new FWXX();
house.setDate(rs.getString("date"));
house.setFwid(rs.getInt("fwid"));
house.setFwxx(rs.getString("fwxx"));
house.setJdid(rs.getInt("jdid"));
house.setLxid(rs.getInt("lxid"));
house.setLxr(rs.getString("lxr"));
house.setShi(rs.getInt("shi"));
house.setTing(rs.getInt("ting"));
house.setTelephone(rs.getString("telephone"));
house.setTitle(rs.getString("title"));
house.setUid(rs.getInt("uid"));
house.setZj(rs.getDouble("zj"));
count++;
houses.add(house);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return houses;}
public boolean get(int id) {
int flag=0;
try {
PreparedStatement ps=con.prepareStatement("select * from TBL_FWXX where fwid=?");
flag=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag>0;
}
public boolean save(FWXX fwxx) {
int flag=0;
try {
PreparedStatement ps=con.prepareStatement("insert into TBL_FWXX(title,zj,uid,jdid,fwxx,shi,ting,telephone,lxr,lxid,date)values(?,?,?,?,?,?,?,?,?,?,?)");
int index=0;
ps.setString(++index, fwxx.getTitle());
ps.setDouble(++index,fwxx.getZj());
ps.setInt(++index,fwxx.getUid());
ps.setInt(++index,fwxx.getJdid());
ps.setString(++index, fwxx.getFwxx());
ps.setInt(++index, fwxx.getShi());
ps.setInt(++index, fwxx.getTing());
ps.setString(++index, fwxx.getTelephone());
ps.setString(++index, fwxx.getLxr());
ps.setInt(++index, fwxx.getLxid());
ps.setString(++index, fwxx.getDate());
flag=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag>0;
}
public List<FWLX> findAllFWLX() {
List< FWLX> list=new ArrayList<FWLX>();
PreparedStatement ps;
try {
ps = con.prepareStatement("select * from tbl_fwlx");
ResultSet rs=ps.executeQuery();
while(rs.next()){
FWLX dto=new FWLX();
dto.setLxid(rs.getInt("lxid"));
dto.setFwlx(rs.getString("fwlx"));
list.add(dto);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
public List<FWXX> findAll(int uid, int page, int pageSize) {
List< FWXX> houses=new ArrayList<FWXX>();
try {
PreparedStatement ps=con.prepareStatement("select * from tbl_fwxx where uid=?",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ps.setInt(1, uid);
//rs可以看做一个游标指针
ResultSet rs=ps.executeQuery();
//定位器
int position=(page-1)*pageSize;
if(position>0){
rs.absolute(position);
}
//计数器
int count=0;
while(rs.next()&&count<pageSize){
FWXX house=new FWXX();
house.setDate(rs.getString("date"));
house.setFwid(rs.getInt("fwid"));
house.setFwxx(rs.getString("fwxx"));
house.setJdid(rs.getInt("jdid"));
house.setLxid(rs.getInt("lxid"));
house.setLxr(rs.getString("lxr"));
house.setShi(rs.getInt("shi"));
house.setTing(rs.getInt("ting"));
house.setTelephone(rs.getString("telephone"));
house.setTitle(rs.getString("title"));
house.setUid(rs.getInt("uid"));
house.setZj(rs.getDouble("zj"));
count++;
houses.add(house);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return houses;
}
public int getTotalPages(int pageSize) {
int totalRecords=0;
int totalPages=0;
try {
PreparedStatement ps=con.prepareStatement("select count(*) from tbl_fwxx");
ResultSet rs=ps.executeQuery();
while(rs.next()){
totalRecords=rs.getInt(1);
totalPages=(totalRecords+pageSize-1)/pageSize;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return totalPages;
}
public FWXX findById(int fwid) {
PreparedStatement ps;
FWXX house=new FWXX();
try {
ps = con.prepareStatement("select * from tbl_fwxx where fwid=?");
ps.setInt(1, fwid);
ResultSet rs=ps.executeQuery();
if(rs.next()){
house.setDate(rs.getString("date"));
house.setFwid(rs.getInt("fwid"));
house.setFwxx(rs.getString("fwxx"));
house.setJdid(rs.getInt("jdid"));
house.setLxid(rs.getInt("lxid"));
house.setLxr(rs.getString("lxr"));
house.setShi(rs.getInt("shi"));
house.setTing(rs.getInt("ting"));
house.setTelephone(rs.getString("telephone"));
house.setTitle(rs.getString("title"));
house.setUid(rs.getInt("uid"));
house.setZj(rs.getDouble("zj"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return house;
}
public int getTotalPages(int uid, int pageSize) {
int totalRecords=0;
int totalPages=0;
try {
PreparedStatement ps=con.prepareStatement("select count(*) from tbl_fwxx where uid=?");
ps.setInt(1, uid);
ResultSet rs=ps.executeQuery();
while(rs.next()){
totalRecords=rs.getInt(1);
totalPages=(totalRecords+pageSize-1)/pageSize;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return totalPages;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -