|
Connect Oracle Database Help class, is to connect the Oracle database method encapsulation, you only need to call in other pages, do not need to repeat the write.
Import java.sql.Connection;
Import java.sql.DriverManager;
Import java.sql.SQLException;
Import oracle.jdbc.driver.OracleDriver;
/ **
* Database connection help class
*
* /
Public class DbHelp {
/ *
* Database connection
* /
Public static Connection lianjie () {
// Database configuration
String driver = "oracle.jdbc.driver.OracleDriver"; // driver
String url = "jdbc: oracle: thin: @localhost: 1521: JBITDB";
String user = "epet";
String pwd = "123456";
Try {
// Step 1: Load the driver
Class.forName (driver); // -> Reflection
Connection conn = DriverManager.getConnection (url, user, pwd);
Return conn;
} Catch (ClassNotFoundException e) {
E.printStackTrace ();
} Catch (SQLException e) {
E.printStackTrace ();
}}
Return null;
}}
}} |
|
|
|