✎
编程开发网
首页
C语言
C++
面试
Linux
函数
Windows
数据库
下载
搜索
当前位置:
首页
->
AI编程基础
->
JAVA
java(JDBC连接数据库)[对Statement进行封装](二)
2014-11-24 09:07:00
·
作者:
·
浏览:
4
标签:
java
JDBC
连接
数据库
Statement
进行
封装
etMessage());
}
try {
columnCount = rsmd.getColumnCount();
} catch (SQLException e1) {
System.out.println(e1.getMessage());
}
List
list = new ArrayList
();
try {
while(rs.next()) {
Map
map = new HashMap
();
for(int i = 1; i <= columnCount; i++) {
map.put(rsmd.getColumnLabel(i), rs.getObject(i));
}
list.add(map);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
closeAll();
}
return list;
}
/**
* 释放所有资源
*/
private void closeAll() {
// 释放结果集连接
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
// 释放声明连接
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
// 释放
数据库
连接
if (connnection != null) {
try {
connnection.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
}
作者:haifengzhilian
首页
上一页
1
2
下一页
尾页
2
/2/2