SQL Server Technical Summary
The default Instance name for ms SQL Server is SQLExpress and the default TCP/IP Port Number is 1433. When a new instance is created instead of the default instance, the default port number is dynamic, therefore, you must specify the corresponding port number. The setting method is as follows: in configuration management, select the corresponding instance in SQL Server network configuration, set the dynamic TCP port in IPALL In the TCP/IP label.
When using SQL Server Management Studio to connect to a database, the Server name format is as follows:
Server IP address, available port number \ [server instance name]
When using Java to connect to the database, the full connection mode has relatively good compatibility.
Public static void main (String [] args ){
String driverName = "com. microsoft. sqlserver. jdbc. SQLServerDriver"; // load the JDBC driver
String dbURL = "jdbc: sqlserver: // localhost: 16103; instanceName = sql2008; DatabaseName = aaaaa"; // connect to the specified database instance
// String dbURL = "jdbc: sqlserver: // localhost: 1433; instanceName = SQLExpress; DatabaseName = aaaaa"; // connect to the default database instance
String userName = "sa"; // Default User Name
String userPwd = "jszx6217"; // User Password
Connection dbConn;
Try {
Class. forName (driverName );
DbConn = DriverManager. getConnection (dbURL, userName, userPwd );
System. out. println ("Connection Successful! "); // If the Connection is Successful, the console outputs Connection Successful!
} Catch (Exception e ){
E. printStackTrace ();
}
}
The connection parameters for connecting to ms SQL SERVER in Java are:
<Strong> "jdbc: sqlserver: // ip address: port number; instanceName = Instance name; DatabaseName = database name" </strong>
This article permanently updates the link address: