[Java] Oracle 数据库连接类 →→→→→进入此内容的聊天室

来自 , 2019-04-17, 写在 Java, 查看 117 次.
URL http://www.code666.cn/view/647bba34
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4.  
  5. /**
  6.  * Oracle 数据库连接类
  7.  */
  8. public class DatabaseConnection {
  9.         public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
  10.         public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:orcl";
  11.         public static final String DBUSER = "system";
  12.         public static final String DBPASSWORD = "root";
  13.         private Connection conn = null;
  14.  
  15.         public DatabaseConnection() {
  16.                 try {
  17.                         Class.forName(DBDRIVER);
  18.                         this.conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD);
  19.                 } catch (ClassNotFoundException e) {
  20.                         e.printStackTrace();
  21.                 } catch (SQLException e) {
  22.                         e.printStackTrace();
  23.                 }
  24.         }
  25.  
  26.         public Connection getConnection() {
  27.                 return this.conn;
  28.         }
  29.  
  30.         public void close() {
  31.                 if (this.conn != null) {
  32.                         try {
  33.                                 this.conn.close();
  34.                         } catch (SQLException e) {
  35.                                 e.printStackTrace();
  36.                         }
  37.                 }
  38.         }
  39. }

回复 "Oracle 数据库连接类"

这儿你可以回复上面这条便签

captcha