PreparedStatement如果用于多项(查询、修改或删除、插入)操作的话,是否关闭一次???
intresult=0;StringcontrastSql=查询语句StringBufferinserSql=newStringBuffer();Connectionco...
int result = 0;
String contrastSql = 查询语句
StringBuffer inserSql = new StringBuffer();
Connection conn = this.jdbcUtil.getCon();
PreparedStatement ps = conn.prepareStatement(contrastSql);
ResultSet rs = ps.executeQuery();
List rsList = new ArrayList();
Map rsMap = null;
while(rs.next()){
rsMap = new HashMap();
。。。。。。。。。
rsList.add(rsMap);
}
rs.close();
ps.close();
if(rsList.size()>0){
inserSql.append("INSERT INTO 表").append(contrastSql);
PreparedStatement ps1 = conn.prepareStatement(inserSql.toString());
result = ps1.executeUpdate();
System.out.println("插入成功了"+rsList.size()+"条数据");
rs.close();
ps1.close();
}
this.jdbcUtil.closed(); 展开
String contrastSql = 查询语句
StringBuffer inserSql = new StringBuffer();
Connection conn = this.jdbcUtil.getCon();
PreparedStatement ps = conn.prepareStatement(contrastSql);
ResultSet rs = ps.executeQuery();
List rsList = new ArrayList();
Map rsMap = null;
while(rs.next()){
rsMap = new HashMap();
。。。。。。。。。
rsList.add(rsMap);
}
rs.close();
ps.close();
if(rsList.size()>0){
inserSql.append("INSERT INTO 表").append(contrastSql);
PreparedStatement ps1 = conn.prepareStatement(inserSql.toString());
result = ps1.executeUpdate();
System.out.println("插入成功了"+rsList.size()+"条数据");
rs.close();
ps1.close();
}
this.jdbcUtil.closed(); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询