package com.cjm.dbc;

import java.sql.*;

/**
* @author cjm
* 使用JDBC 连接 oracle 数据库
*/
public class DatabaseConnection {

// 数据库驱动
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
// 连接字符串
public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:sa";
// 数据库帐号
public static final String DBUSER = "cjm";
// 数据库密码
public static final String DBPASSWORD = "cjm";
private Connection conn = null;

public DatabaseConnection() {
try {
// 加载驱动
Class.forName(DBDRIVER);
try {
this.conn = DriverManager.getConnection(DBURL, DBUSER,DBPASSWORD);
}
catch (SQLException e) {
e.printStackTrace();
}
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
}

//获取数据库链接
public Connection getConnection() {
return this.conn;
}

// 数据库链接关闭
public void close() {
if (this.conn != null) {
try {
this.conn.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2021-08-28
  • 2021-12-09
  • 2021-12-09
  • 2021-12-10
猜你喜欢
  • 2022-02-20
  • 2021-12-16
  • 2021-11-14
  • 2021-10-21
  • 2021-12-03
  • 2021-07-01
  • 2022-12-23
相关资源
相似解决方案