Java connects SQLServer2005 with JDBC

Source: Internet
Author: User

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

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.