Commit 22b7f356 by flying-cattle

连接sql优化

parent 151e1ef3
...@@ -39,11 +39,11 @@ public class EntityInfoUtil { ...@@ -39,11 +39,11 @@ public class EntityInfoUtil {
try { try {
con = DriverManager.getConnection(bi.getDbUrl(), bi.getDbName(), bi.getDbPassword()); con = DriverManager.getConnection(bi.getDbUrl(), bi.getDbName(), bi.getDbPassword());
pstemt = con.prepareStatement(sql); pstemt = con.prepareStatement(sql);
ResultSet executeQuery = pstemt.executeQuery(); ResultSet rs = pstemt.executeQuery();
while (executeQuery.next()) { while (rs.next()) {
String column = executeQuery.getString(1); String column = rs.getString(1);
String jdbcType = executeQuery.getString(2); String jdbcType = rs.getString(2);
String comment = executeQuery.getString(3); String comment = rs.getString(3);
PropertyInfo ci=new PropertyInfo(); PropertyInfo ci=new PropertyInfo();
ci.setColumn(column); ci.setColumn(column);
if (jdbcType.equalsIgnoreCase("int")) { if (jdbcType.equalsIgnoreCase("int")) {
...@@ -64,13 +64,25 @@ public class EntityInfoUtil { ...@@ -64,13 +64,25 @@ public class EntityInfoUtil {
columns.add(ci); columns.add(ci);
} }
bi.setCis(columns); bi.setCis(columns);
// 完成后关闭
rs.close();
pstemt.close();
con.close();
return bi; return bi;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("自动生成实体类错误:"+e.getMessage()); throw new RuntimeException("自动生成实体类错误:"+e.getMessage());
} finally { } finally {
pstemt.close(); // 关闭资源
con.close(); try{
if(pstemt!=null) pstemt.close();
}catch(SQLException se2){
}// 什么都不做
try{
if(con!=null) con.close();
}catch(SQLException se){
se.printStackTrace();
}
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment