java连接数据库的工具包.
package com.util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class DBhelper { /** * 数据库用户名 */ private static final String USERNAME="test"; /** * 数据库密码 */ private static final String PASSWORD="123456"; /** * 加载数据库驱动 */ private static final String DRIVER="oracle.jdbc.OracleDriver"; /** * 获取数据库地址 */ private static final String URL="jdbc:oracle:thin:@localhost:1521:orcl"; /** * 获取数据库连接 */ public static Connection getOracleConnection(){ Connection conn = null; try { Class.forName(DRIVER); conn = DriverManager.getConnection(URL, USERNAME, PASSWORD); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } /** * 释放资源 */ public static void destroy(Connection conn, Statement st, ResultSet rs){ if(conn!=null){ try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } if(st!=null){ try { st.close(); } catch (SQLException e) { e.printStackTrace(); } } if(rs!=null){ try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } conn=null; st=null; rs=null; } }
原文:http://www.cnblogs.com/514929hgy/p/7193901.html