java连接oracle数据库

public class DbConn {
	private static Connection conn = null;

	private DbConn() {
		try {
			// Class.forName("oracle.jdbc.driver.OracleDriver");
			DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
			conn = DriverManager.getConnection(
					"jdbc:oracle:thin:@wshaohui:1521:ibm", "programe_user",
					"123");
			System.out.println("========================");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static Connection getOraConnection() {
		if (conn == null) {
			new DbConn();
		}
		return conn;
	}

        // 关闭数据库连接的静态方法
	public static void closeConn(Connection conn) {
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				System.out.println("关闭连接错误...");
				e.printStackTrace();
			}
		}
	}
}
 

你可能感兴趣的:(java,oracle,jdbc,IBM)