Sqlserverdriver configuration method jdbc connection to sqlserver

Source: Internet
Author: User
Tags microsoft sql server 2005 strong password

1. Download the driver.

: Http://download.microsoft.com/download/8/ B /D/8BDABAE2-B6EA-41D4-B903-7916EF3690EF/sqljdbc_1.2.2323.101_enu.exe

First download sql2005jdbcdriver sqljdbc_2.0.1008.2_enu.exe (sql2005 and sql2008 are supported after version 1.1)

The downloaded package can be decompressed without installation. You can place the package wherever you want, for example, you can put the package

In the C: \ Program Files directory. The path of the sqljdbc. jar package is
Copy codeThe Code is as follows:
C: \ Program Files \ Microsoft SQL Server 2005 JDBC Driver \ sqljdbc_1.2 \ enu \ sqljdbc. jar

2. Configure the Tomcat server.

Make sure that you have installed Tomcat. Open the Monitor Tomcat server and add the sqljdbc. jar package path under Java Classpath on the Java tab.
Copy codeThe Code is as follows:
C: \ Program Files \ Microsoft SQL Server 2005 JDBC Driver \ sqljdbc_1.2 \ enu \ sqljdbc. jar

(Separate the two jar packages with semicolons (;). Restart the Tomcat server to complete Tomcat configuration;

3. Configure the sql2005 server.

Configure the TCP port:
Copy codeThe Code is as follows:
Start> All Programs> Microsoft SQL Server 2005> Configuration tool> SQL Server Configuration Manager

-> SQL Server 2005 network configuration-> MSSQLSERVER protocol; Enable "TCP/IP"; double-click "TCP/IP"-> "IP address"-> "IPAll"

-> Add the default "1433" for "TCP port ". Restart the sql2005 server to complete the configuration of the sql2005 server.

Iv. copy backup files

Find the sqljdbc_auth.dll file in the sqljdbc driver you downloaded. For example, the decompressed directory is C: \ Program Files, so I

The sqljdbc_auth.dll file in
Copy codeThe Code is as follows:
C: \ Program Files \ Microsoft SQL Server 2005 JDBC Driver \ sqljdbc_1.2 \ enu \ auth \ x86 \ sqljdbc_auth.dll

Put the found file in the C: \ WINDOWS \ system32 directory. This is a dynamic Runtime Library, which must not be less.

5. Write a test file and test it. (The appendix is provided at the end of the article)

Remember: you have made changes to the server (whether Tomcat or sql2005 server configuration, you must restart the server to make the changes take effect)

If not, try opening more services to the sql2005 server as follows:

1. Peripheral application configuration:

Microsoft SQL Server 2005-> Configuration tool-> SQL Server peripheral application configurator-> service and connected peripheral application configurator->

① Select SQLEXPRESS-> Database Engine-> remote connection-> Local Connection and remote connection-> use TCP/IP and named pipes at the same time;

② Select SQL Server Browser> service> Start type to "automatic"> Application> Start> OK.

2. Modify the default logon authentication mode. Because SAS is installed in the "Windows Authentication Mode" mode by default during installation, SAS logon is disabled.
If you change the Authentication Mode to "SQL Server and Windows Authentication Mode", SAS logon is still disabled, so you need to enable the sa Logon account ):

① In the object Resource Manager of SQL Server Management Studio, choose security> Logon Name> sa> Properties> General>

Set sa password and Confirm Password as strong password-> Status-> logon-> enable-> OK;

② In the object Resource Manager of SQL Server Management Studio, right-click the Server and choose Properties> Security> Server Authentication.

Select "SQL Server and Windows Authentication Mode"-> OK-> OK.

3. Disable the firewall.

Note:

Note the differences between 2000 and 2005 when writing the connection code:

Connect to SqlServer2000
Copy codeThe Code is as follows:
Class. forName ("com. microsoft. jdbc. sqlserver. SQLServerDriver ");
URL = "jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = tempdb ";

Connect to SqlServer2005
Copy codeThe Code is as follows:
Class. forName ("com. microsoft. sqlserver. jdbc. SQLServerDriver ");
URL = "jdbc: sqlserver: // localhost: 1433; DatabaseName = tempdb ";

Appendix:
Copy codeThe Code is as follows:
Import java. SQL .*;

Public class Test {
Public static void main (String [] srg ){
String driverName = "com. microsoft. sqlserver. jdbc. SQLServerDriver"; // load the JDBC driver
String dbURL = "jdbc: sqlserver: // localhost: 1433; DatabaseName = sample"; // connect to the server and database sample
String userName = "sa"; // Default User Name
String userPwd = "123456"; // 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 ();
}
}
}

In addition, after writing the above test code, import the jar package of the jdbc driver to the Eclicpse project:

Right-click Project Test-> properties-> select Java Build Path on the left-> class library (Libaries)-> Add External JARs (Add External JARs)

Select the jar file in the downloaded driver

Click OK.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.