怎么处理数据库连接失败异常
发布网友
发布时间:2022-04-23 23:46
我来回答
共1个回答
热心网友
时间:2023-10-14 02:54
public List selectMark(Integer mark) {
jdbc = new JDBConnection();
connection = jdbc.connection;
List list = new ArrayList();
GoodsForm goods = null;
String sql = "";
try {
if(mark==0||mark==1||mark==null){
sql = "select * from tb_goods where spsd=1 order by id DESC";
}else if(mark==2){
sql = "select * from tb_goods where mark="+mark+" and spsd=1 and sysdate between begin_time and end_time order by id DESC";
}else if(mark==3){
sql = "select * from tb_goods where mark="+mark+" and spsd=1 order by id DESC";
}else if(mark==4){
sql = "select * from tb_goods where mark="+mark+" and spsd=1 order by id DESC";
}
ps = connection.prepareStatement(sql);
//ps.setInt(1, mark.intValue());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
goods = new GoodsForm();
goods.setId(Integer.valueOf(rs.getString(1)));
goods.setBig(Integer.valueOf(rs.getString(2)));
goods.setSmall(Integer.valueOf(rs.getString(3)));
goods.setName(rs.getString(4));
goods.setFrom(rs.getString(5));
goods.setIntroce(rs.getString(6));
goods.setCreaTime(rs.getString(7));
goods.setNowPrice(Float.valueOf(rs.getString(8)));
goods.setFreePrice(Float.valueOf(rs.getString(9)));
goods.setNumber(Integer.valueOf(rs.getString(10)));
goods.setPriture(rs.getString(11));
goods.setMark(Integer.valueOf(rs.getString(12)));
goods.setSpsd(Integer.valueOf(rs.getString(13)));
if (rs.getString(14) != null) {
goods.setSalesNumber(Integer.valueOf(rs.getString(14)));
} else {
goods.setSalesNumber(0);
}
if (rs.getString(15) != null) {
goods.setSpdm(Integer.valueOf(rs.getString(15)));
} else {
goods.setSpdm(0);
}
goods.setSpec(rs.getString(16));
goods.setUnit(rs.getString(17));
goods.setBarCode(rs.getString(18));
goods.setPurchase_price(rs.getString(19));
goods.setSpecialOffer(rs.getString(20));
list.add(goods);
}
rs.close();
ps.close();
connection.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return list;
}