求java大神看如下代码有何问题,运行一段时间后就执行不了了,是否是数据库连接的问题
Contextctx=newInitialContext();DataSourceds=(DataSource)ctx.lookup("java:comp/env/jk-...
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jk-ds");
Connection con = ds.getConnection();
PreparedStatement ps ;
//导入前删除数据
ps = con.prepareStatement("delete from EEIM_JCJK where mon ="+pt.getD_date().replace("-", "").substring(0,6)+" and COPY_METER_SECT_NO = '"+pt.getTqbh()+"' ");
ps.execute();
String sql = "Insert into EEIM_JCJK "
+ "(MON, MON_SN, USER_NO, ASSETS_NO, "
+ "OUTGOING_NO,FUNCTION_CODE, START_NUM,END_NUM,"
+ "REACTIVE_START_NUM,REACTIVE_END_NUM,PAR_START_NUM,"
+ "PAR_END_NUM,UUID,CREATE_TIME,business_area_code,copy_meter_sect_no) "
+ "Values (?,1, ?, ?,?, 'Y',?,?,0,0,0,0,?,?,?,?) " ;
ps = con.prepareStatement(sql);
for (int i = 0; i < list.size(); i++) {
pt = (ParameterSetting) list.get(i);
if (pt.getYgzds()!=null&&pt.getYgzds().startsWith(".")) {
pt.setYgzds("0"+pt.getYgzds());
}
//出厂编号处理
String jlbbh2 = "" ;
if(pt.getJlbbh2()!=null){
jlbbh2 = pt.getJlbbh2() ;
int len = pt.getJlbbh2().length();
if (len>=6) {
pt.setJlbbh2(jlbbh2.substring(0,6));
}else if (len==5) {
pt.setJlbbh2("0"+jlbbh2);
}else if (len==4) {
pt.setJlbbh2("00"+jlbbh2);
}else if (len==3) {
pt.setJlbbh2("000"+jlbbh2);
}else if (len==2) {
pt.setJlbbh2("0000"+jlbbh2);
}else if (len==1) {
pt.setJlbbh2("00000"+jlbbh2);
}
}
UUID uuid = UUID.randomUUID();
ps.setString(1, pt.getMonth());
ps.setString(2, pt.getYhdabh());
ps.setString(3, pt.getJlbbh());
ps.setString(4, pt.getJlbbh2());
ps.setString(5, pt.getYgzds());
ps.setString(6, pt.getYgzds());
ps.setString(7, uuid.toString().replace("-", ""));
ps.setString(8, pt.getCbsj());
ps.setString(9, pt.getYyzbh());
ps.setString(10, pt.getTqbh());
ps.addBatch();
if(i%100==0){
ps.executeBatch();
ps.clearBatch();
}
}
ps.executeBatch();
ps.close();
//关闭连接
con.close();
还是数据库连接用完了,这方面不太知道,求大神指点,代码是否有硬伤 展开
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jk-ds");
Connection con = ds.getConnection();
PreparedStatement ps ;
//导入前删除数据
ps = con.prepareStatement("delete from EEIM_JCJK where mon ="+pt.getD_date().replace("-", "").substring(0,6)+" and COPY_METER_SECT_NO = '"+pt.getTqbh()+"' ");
ps.execute();
String sql = "Insert into EEIM_JCJK "
+ "(MON, MON_SN, USER_NO, ASSETS_NO, "
+ "OUTGOING_NO,FUNCTION_CODE, START_NUM,END_NUM,"
+ "REACTIVE_START_NUM,REACTIVE_END_NUM,PAR_START_NUM,"
+ "PAR_END_NUM,UUID,CREATE_TIME,business_area_code,copy_meter_sect_no) "
+ "Values (?,1, ?, ?,?, 'Y',?,?,0,0,0,0,?,?,?,?) " ;
ps = con.prepareStatement(sql);
for (int i = 0; i < list.size(); i++) {
pt = (ParameterSetting) list.get(i);
if (pt.getYgzds()!=null&&pt.getYgzds().startsWith(".")) {
pt.setYgzds("0"+pt.getYgzds());
}
//出厂编号处理
String jlbbh2 = "" ;
if(pt.getJlbbh2()!=null){
jlbbh2 = pt.getJlbbh2() ;
int len = pt.getJlbbh2().length();
if (len>=6) {
pt.setJlbbh2(jlbbh2.substring(0,6));
}else if (len==5) {
pt.setJlbbh2("0"+jlbbh2);
}else if (len==4) {
pt.setJlbbh2("00"+jlbbh2);
}else if (len==3) {
pt.setJlbbh2("000"+jlbbh2);
}else if (len==2) {
pt.setJlbbh2("0000"+jlbbh2);
}else if (len==1) {
pt.setJlbbh2("00000"+jlbbh2);
}
}
UUID uuid = UUID.randomUUID();
ps.setString(1, pt.getMonth());
ps.setString(2, pt.getYhdabh());
ps.setString(3, pt.getJlbbh());
ps.setString(4, pt.getJlbbh2());
ps.setString(5, pt.getYgzds());
ps.setString(6, pt.getYgzds());
ps.setString(7, uuid.toString().replace("-", ""));
ps.setString(8, pt.getCbsj());
ps.setString(9, pt.getYyzbh());
ps.setString(10, pt.getTqbh());
ps.addBatch();
if(i%100==0){
ps.executeBatch();
ps.clearBatch();
}
}
ps.executeBatch();
ps.close();
//关闭连接
con.close();
还是数据库连接用完了,这方面不太知道,求大神指点,代码是否有硬伤 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询