SQL Server技術總結

來源:互聯網
上載者:User

SQL Server技術總結

MS SQL Server預設執行個體名稱是SQLExpress且預設的TCP/IP連接埠號碼是1433,當不使用預設執行個體而是建立的執行個體時,預設的連接埠號碼是動態,所以必須要指定相應的連接埠號碼,設定方式為:在組態管理中,SQL Server網路設定中選擇相應的執行個體,然後設定TCP/IP中IP標籤中的IPALL中的TCP動態連接埠。

在使用SQL Server Management Studio串連資料庫時,伺服器名稱格式如下

伺服器IP地址,可用連接埠號碼\[伺服器執行個體名]

當使用Java串連資料庫時,使用全面的串連方式相容性相對比較好。

public static void main(String[] args) {
    String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //載入JDBC驅動
    String dbURL = "jdbc:sqlserver://localhost:16103;instanceName=sql2008; DatabaseName=aaaaa"; //串連到指定的資料庫執行個體
    //String dbURL = "jdbc:sqlserver://localhost:1433;instanceName=SQLExpress; DatabaseName=aaaaa"; //串連到預設的資料庫執行個體
    String userName = "sa"; //預設使用者名
    String userPwd = "jszx6217"; //使用者密碼
    Connection dbConn;
    try {
    Class.forName(driverName);
    dbConn = DriverManager.getConnection(dbURL,userName, userPwd);
    System.out.println("Connection Successful!"); //如果串連成功 控制台輸出Connection Successful!
    } catch (Exception e) {
    e.printStackTrace();
    }
 }

在Java中的萬能串連MS SQL SERVER的串連參數為:

<strong>"jdbc:sqlserver://IP地址:連接埠號碼;instanceName=執行個體名;DatabaseName=資料庫名"</strong>

本文永久更新連結地址:

相關文章

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.