有谁能给一个实际开发中的 数据库通用类 来参考?
[email protected] 谢谢~!
[email protected] 谢谢~!
解决方案 »
- tomcat中,jsp页面中<img src="中文图片名">无法显示
- 技术经理让我做个审查和删除,要求返回boolean,并以xml流返回,用Struts1或Struts2都可以,该怎么做?
- spring applicationContext.xml模块?
- WebApplicationException
- 显示列表标签问题
- 关于jsf弹出popup画面的问题
- 谁有操作存储过程的封装类
- Servlet是连接MySQL数据库,我想把数据库改成SQLSERVER2000...请进~~~`
- jsp网页,我想自动生成表格
- 谁有完整的替代函数!
- usb外界 键盘不能用了是键盘的事还是驱动程序的事?
- struts 的bean write 问题
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class DbUtils {
protected DbUtils() {
} public static void register(String driverName) {
try {
Class.forName(driverName);
} catch (Exception ex) {
throw new RuntimeException("Database Driver Register Error: "
+ driverName, ex);
}
} public static Connection getConn(String url, String username,
String password) {
try {
return DriverManager.getConnection(url, username, password);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
} public static void close(Connection conn) {
close(conn, null, null);
} public static void close(Connection conn, Statement state) {
close(conn, state, null);
} public static void close(Connection conn, Statement state, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (Exception ex) {
System.err.println(ex);
} finally {
rs = null;
}
} if (state != null) {
try {
state.close();
} catch (Exception ex) {
System.err.println(ex);
} finally {
state = null;
}
} if (conn != null) {
try {
conn.close();
} catch (Exception ex) {
System.err.println(ex);
} finally {
conn = null;
}
}
}
}