[java]代码库
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* Oracle 数据库连接类
*/
public class DatabaseConnection {
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:orcl";
public static final String DBUSER = "system";
public static final String DBPASSWORD = "root";
private Connection conn = null;
public DatabaseConnection() {
try {
Class.forName(DBDRIVER);
this.conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException 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();
}
}
}
}