One: Configuration
The first step: Download the SQLServer2005 driver package http://www.microsoft.com/downloads/zh-cn/details.aspx online? Familyid=c47053eb-3b64-4794-950d-81e1ec91c1ba, download is a webpage, do not worry, rest assured download, download completed after the Web page, click to download
Step two: Download complete Sqljdbc_1.2.2828.100_chs.exe, double click, select Upzip
Step three: In the computer right-click "Properties"-"Advanced system Settings"-"Advanced"-"Environment variable setting"-"System variable", add Sqljdbc.jar path in "CLASSPATH", for example D:\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.2\chs\sqljdbc.jar. (Note: After I set this step or I am not prompted to find the driver package)
Fourth step: Open Eclipse, right-click "Bulid Path"-"Add External Archives"-"Select Sqljdbc.jar" on the project you are building
(Note, error message "Com.microsoft.sqlserver.jdbc.SQLServerException: No driver configured for integrated authentication")
Fifth step: Find the "Auth folder"-"x86 folder"-"Sqljdbc_auth.dll" in the unpacked folder of the downloaded driver package and copy it to windows-"System32.
Two: Connection
String drivername= "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; //driver package connection string
String dburl= "Jdbc:sqlserver://localhost:1433;integratedsecurity=true;databasename=csmsdzgs";
Database connection string (note port writing, default is 1433, can be in sqlserver2005-"Configuration Tool"-"SQL Server")
Config manager-"SQL Server2005 Network Configuration"-"MSSQLSERVER Protocol"-"TCP/IP (required on
"-" TCP/IP Properties "-" IPs "-" TCP port ")
Connection Dbconn;Create a database Connection object
try{
Class.forName (drivername);
Dbconn=drivermanager.getconnection (Dburl);
System.out.println ("SQLSERVER2005 Connection success!"); //Connect to Database
}catch (Exception e) //Catch exception
{
E.printstacktrace ();
}
Java connects SQLServer2005 with JDBC