解决方案 »
- 关于facebookAPI问题
- 请问如何在myeclipse中自动生成spring的接口类和实现类?
- Java EE防伪技术?
- 刚刚想到两个问题,请教下大家。
- 讨论J2EE分布式开发问题,欢迎参加!!!
- java+tomcat怎样调用mysql数据库啊。
- 问几个最基本的问题(没学过J2EE)
- 翻译:EJB in a Nutshell
- 想从一个XML文件中读出我想要的数据,可是不知该怎么用?不要遍历文件树,只需要分别提取指定的数据,使用DOM技术,谁能给我一个例子,指
- java项目中的config配置中的JFinal.start("WebRoot", 8088, "/", 5);这句代码是什么意思,怎么理解??求大神解答,感谢
- security登陆后无法跳转成功页面
- Mybatis的Update不能返回影响输数吗?
public class DB {
private static String url="jdbc:oracle:thin:@localhost:1521:orcl";
private static String user="scott";
private static String password="tiger";
private DB(){ }
static{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
throw new ExceptionInInitializerError(e);
}
}
public static Connection getConnection() throws SQLException{
return DriverManager.getConnection(url,user,password);
}
public static void Free(Connection conn,PreparedStatement ps,ResultSet rs){
try {
rs.close();
}
catch (SQLException e)
{
}
try {
ps.close();
}
catch (SQLException e)
{
}
try {
conn.close();
}
catch (SQLException e)
{
}
}在别的类中当需要关闭Connection时调用DB.free(conn,ps,rs);
定义一个Connection conn = DB.getConnection();try{
Connection conn = DB.getConnection();
}finally{
if(conn!=null){
conn.close();
}
}在这里关闭的conn就是你原先类中的连接。