Java Oracle 連結資料庫
阿新 • • 發佈:2018-11-19
連線資料庫
//服務類
private Connection conn = null;
public NetDealer_Service(){
conn = com.zse.connector.OracleConnector.getconn();
}
//資料庫類
public class OracleConnector {
private static Connection conn = null;
private OracleConnector(){}
public static Connection getconn(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@127.0.0.1:1521:xe";
String user = "mysystem";//自己的資料庫名稱
String password = "495";//資料庫密碼
conn = DriverManager.getConnection(url, user, password);
if(conn != null){
System.out.println("連線成功");
}
}catch (Exception e) {
System.out.println("連線失敗");
}
return conn;
}
}