java数据库连接模板代码通用收集

时间:2023-12-29 19:28:38
package org.lxh.dbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException; public class DatabaseConnection {
private static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
private static final String DBURL = "jdbc:oracle:thin:@localhost:1521:MLDN";
private static final String DBUSER = "scott";
private static final String DBPASSWORD = "tiger";
private Connection conn; 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();
}
}
}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。