JDBC configuration method for SQL Server _java

Source: Internet
Author: User
Tags microsoft sql server

Using a database in 1.java requires the use of JDBC (Java database connection) to connect and manipulate

Download Address: http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774

2. After the completion of the decompression to a plate, such as: G:\Program FILES\SQLJDBC;

3.Microsoft JDBC DRIVR 4.0 for SQL Server supports only jdk1.6 and above, with two packages internally: Sqljdbc4.jar and Sqljdbc.jar

4. Put the Sqljdbc4.jar into the Java installation package

such as: G:\Program Files\java\jdk1.7.0_05\jre\lib\ext (Must be:. \jdk1.7.0_05\jre\lib\ext)

PS: Only put Sqljdbc4.jar into the package, Sqljdbc.jar is not put, because there can only be a JDBC, two of the same put the error

5. Start->microsoft SQL Server 2008 R2 (or other version)-> Configuration Tool->sql Server Configuration Manager

->sql Server 2008 R2 Network Configuration->mssqlserver protocol;

Enable TCP/IP, and double-click TCP/IP->-> "ipall"-> "TCP port" to add the default "1433".

6. Modify the Default logon authentication mode (the sa login is disabled because it was installed by default in Windows authentication mode during the installation process)

① first log in with Windows identity, then right-click the "SA"-> property-> the security-> logon name->->

Set the password and confirmation password for the sign-in name SA to 123456-> State-> login-> enable-> OK;

② then exits, restarts the database, uses SQL Server and Windows Authentication mode to log in, user name SA, password 123456, login successful database set up

7. Open Eclipse, New Java Project

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 ();
}
}
}

8. If the operation is successful, it indicates that the configuration is successful!

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.