jdk1.7 JDBC Connection SQL Server2008

Source: Internet
Author: User

Router Network: http://www.ming4.com/news/2355.html

Jackie's Blog: http://blog.163.com/jackie_howe/blog/static/19949134720125173539380/

Configuration of Part 1:sqlserver 2008

0. Before you connect to the database, you must ensure that SQL Server 2008 is in SQL Server authentication, not Windows Authentication mode.

1. After installing SQL Server 2008, run start → All programs →microsoft SQL Server 2008→ Configuration tool →sql Server Configuration Manager, locate the MSSQLSERVER protocol on the left side of the open window, right-click on the right TCP/IP, select enabled. If named Pipes is not enabled, it is also set to Enabled.

2. Double-click TCP/IP on the right, select the address tag in the pop-up window, set the TCP port in IPAll to 1433 and the enabled option above to Yes.

3. Restart the database, use the command to test 1433 port open Start menu → run cmd→ at the command prompt input: telnet 127.0.0.1 1433

Part 2:microsoft JDBC Driver for SQL Server

Download the driver for JDBC SQL Server first.

Link: http://pan.baidu.com/s/1bn8hGtx Password: zv3g

Decompression, for jdk1.7 version above, you can put the sqljdbc4.jar file in the Java Lib file and Tool.jar together.

Mine is placed under the C:\Program Files\java\jdk1.7.0_71\lib\ext folder.

And put the "sqljdbc_auth.dll" in the download file in C:\windows\system32.

Part 3: Testing

Create a new project in Eclipse, right-click the project--properties--java Build path--libraries--add External JARs and add the Sqljdbc4.jar package to the project

To create a new class in the project, the code is as follows

public class Test {public static void main (String[]args) {String drivername = " Com.microsoft.sqlserver.jdbc.SQLServerDriver ";  Load JDBC Driver string dburl = "jdbc:sqlserver://localhost:1433; Databasename=ztest ";  Connect the server and database, assuming the new database is named zteststring userName = "sa";  Suppose the SA is your user name string userpwd = "123";  Suppose the password is 123Connection dbconn;try {class.forname (drivername);d bconn = Drivermanager.getconnection (Dburl, UserName, USERPWD); System.out.println ("Connection successful!");  If the connection succeeds console output connection successful!} catch (Exception e) {e.printstacktrace ();}}}

If successful, the console outputs "Connection successful!"

jdk1.7 JDBC Connection SQL Server2008

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.