First, download the driver.
Download Address: Http://download.microsoft.com/download/8/B/D/8BDABAE2-B6EA-41D4-B903-7916EF3690EF/sqljdbc_1.2.2323.101_enu.exe
First download to SQL2005JDBC driver Sqljdbc_2.0.1008.2_enu.exe (support for sql2005,2.0 after version number 1.1 sql2008)
The download is a decompression can be used, do not need to install, you can put this bag anywhere you want to put, for example, you put the bag
Under the C:\Program files directory. and the path to the Sqljdbc.jar package is
Copy Code code as follows:
C:\Program Files\Microsoft SQL Server Driver\sqljdbc_1.2\enu\sqljdbc.jar JDBC
Second, configure the Tomcat server.
Make sure you have Tomcat installed. Open the monitor Tomcat server and add the Sqljdbc.jar package path under Java classpath of the Java tab
Copy Code code as follows:
C:\Program Files\Microsoft SQL Server Driver\sqljdbc_1.2\enu\sqljdbc.jar JDBC
(Two differences between my jar packs are separated by semicolons ";"), restart the Tomcat server, so that the Tomcat configuration can be completed;
Third, configure the sql2005 server.
To configure a TCP port:
Copy Code code 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->"-> "Ipall"
-> the "TCP port" entry to add the default "1433". Restart the sql2005 server, which completes the configuration of the sql2005 server.
Iv. Copy and prepare documents
Find the Sqljdbc_auth.dll file in the SQLJDBC driver you downloaded, such as C:\Program files in the directory I unpacked, so I
The Sqljdbc_auth.dll file is
Copy Code code as follows:
C:\Program Files\Microsoft SQL Server Driver\sqljdbc_1.2\enu\auth\x86\sqljdbc_auth.dll JDBC
Put the found file into the C:\WINDOWS\system32 directory, this is a dynamic Run-time library, this dongdong must not be less.
Write a test file and test it. (End of article has appendix)
Remember: On the server (whether it is a Tomcat server or a sql2005 server configuration has been changed to make the changes take effect must restart the server)
If you can't fix it, you can try again. Open More services to the SQL2005 server specific operations are as follows:
1. Peripheral application Configuration:
The Microsoft SQL server 2005-> Configuration Tool->sql The Server perimeter configuration-> service and the perimeter configuration of the connection->
① Select sqlexpress->database engine-> remote connection-> local and remote connections-> use TCP/IP and named pipes concurrently;
② Select SQL Server browser-> service-> Startup type to "Auto"-> application-> start-> OK.
2. Modify the default logon authentication mode (because it is installed by default in Windows authentication mode during the installation process, the SA login is prohibited
, you need to enable the SA logon account, even if you change the authentication mode to SQL Server and Windows authentication mode, and the sa login is still disabled:
① in the Object Explorer of SQL Server Management Studio, security-> login-> Right-click "sa"-> properties-> General->
Set the password and confirmation password for the login SA to strong password-> State-> login-> enable-> OK;
② in the Object Explorer of SQL Server Management Studio, right-click the server-> property-> security-> Server Authentication->
Select SQL Server and Windows Authentication mode-> to determine->.
3, shut down the firewall.
Attention:
Note the difference between 2000 and 2005 when writing the connection code:
Connect SqlServer2000
Copy Code code as follows:
Class.forName ("Com.microsoft.jdbc.sqlserver.SQLServerDriver");
URL = "jdbc:microsoft:sqlserver://localhost:1433;databasename=tempdb";
Connect SqlServer2005
Copy Code code as follows:
Class.forName ("Com.microsoft.sqlserver.jdbc.SQLServerDriver");
URL = "jdbc:sqlserver://localhost:1433;databasename=tempdb";
Appendix:
Copy Code code as follows:
Import java.sql.*;
public class Test {
public static void Main (string[] SRG) {
String drivername = "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; Load JDBC Driver
String Dburl = "jdbc:sqlserver://localhost:1433;" Databasename=sample "; Connecting Servers and Databases 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 succeeds to the console output connection successful!
catch (Exception e) {
E.printstacktrace ();
}
}
}
Also, after you write the above test code, import the JDBC driver's jar package in the Eclicpse project:
Right-key Item test-> properties-> Select left Java build path (Java builds path)-> class library (libaries)-> Add external JARs (add External JARs)
Select the jar file in the downloaded driver
And then the point is OK.