jdbc 資料庫的串連(sqlserver oracle)

來源:互聯網
上載者:User

1.sql server 2000資料庫的串連方式:
複製代碼 代碼如下:
Connection con;
public Connection getCon(){
try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");//載入驅動程式
con=DriverManger.getConnection("jdbc:microsoft:sqlServer://localhost:1433;DatabaseName=aa","sa",""); // 試圖建立到給定資料庫 URL 的串連
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
return con;
}

2.sql server 2005資料庫的串連方式:
複製代碼 代碼如下:
Connection con;
public Connection getCon(){
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//載入驅動程式
con=DriverManger.getConnection("jdbc:microsoft:sqlServer://localhost:1433;DatabaseName=aa","sa",""); // 試圖建立到給定資料庫 URL 的串連
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
return con;
}

3.oracle 資料的串連方式
複製代碼 代碼如下:
Connection con;
public Connection getCon(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManger.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:oracle","scott","tiger");
}catch(Exception e){
e.printStackTrace();
}
return con;
}

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.