Link Eclipse and SQL SEVER

Source: Internet
Author: User
Tags stmt sql server management

I. Contents of this article

The process of using JDBC to build bridges between Eclipse and SQL Sever and the problems that may be encountered.

Two. Download of details 1.JDBC driver

It is recommended that you download the Microsoft Official website related to SQL Sever to find the version driver that best suits your SQL.

I am using windows.10 operating system, SQL SEVER EXPRESS (admin login password), Eclipse (JDK configured)

Until (November 11, 2015)

The latest driver for Microsoft: https://www.microsoft.com/zh-cn/download/details.aspx?id=11774

The home page for Microsoft JDBC Driver is: https://msdn.microsoft.com/en-us/data/aa937724.aspx

2 Download Unzip

Download and install the driver version for your operating system according to the system requirements and installation instructions on the download page.

  

Additional attention required to avoid unnecessary hassles is in the installation instructions:

  

3. Find the driver files you need to import eclipse

1. Create a good one Java project in Eclipse and a class with a main function (the process is no longer demonstrated here)

2. Create a new folder in the project (the name is arbitrary, here for convenience, called Lib).

3. In the extracted JDBC folder (Microsoft jdbc Driver 4.2 for SQL Server)

Locate the CHS folder by following the path: Microsoft JDBC Driver 4.2 for SQL server\sqljdbc_4.2

Open the CHS file, and in the following file, locate the file that is appropriate for your version of the suffix named ". Jar".

Here I chose the Sqljdbc42.jar driver file.

   

4. Import the jar file into eclipse

1. Copy the. jar file found in the previous step

2. Switch back to Eclipse and right click on the new Lib folder

3. Paste the jar file into the Lib file

4. Right click on the jar file in the Lib folder

5. Select the build path-->> configuration build path (English words I forget, but this option is located below the Red xx, the next word in parentheses is the option of B)

The following scenarios are imported:

    

5. The work in Eclipse is complete, and now it's done in SQL Sever (where the default is to build a database, not too much elaboration of the process)

1. For convenience, log in as Database administrator (SA)

2. Establish a database, here for convenience, named: "AdventureWorks"

3. Create a table in the "AdventureWorks" database: For convenience, the name is "S".

4. If the "S" table is not established using T-SQL statements, the table needs to be designed.

5. Insert the data into the table "S".

6. So far, smooth, no need to touch the SQL sever, otherwise, then said.

7. I've created a sample table:

    

6. Go back to eclipse and test the connection to the database.

1. Enter the code according to the example below

2. Take a look at the code comment

Note: Import the package name and package name, unless you create the same as me, do not feel free to "crrl+c" and "Ctrl + V".

1  PackageHelloWorld//Package Name2 3 //the imported package name4 Importjava.sql.Connection;5 ImportJava.sql.DriverManager;6 ImportJava.sql.ResultSet;7 Importjava.sql.Statement;8 9 //class nameTen  Public classKelion { One  A     //1433 is the TCP port -     //DatabaseName is the database name -     //User is the login name of the SQL administrator (the default SA) the     //password according to their own actual situation, the "*" is a demonstration (want my password, want to beautiful) -      -     StaticString Connectionurl = "jdbc:sqlserver://localhost:1433;" -+ "Databasename=adventureworks;" ++ "USER=SA;" -+ "password=******;"; +              A     //Main function at      Public Static voidMain (string[] args)throwsexception{ -         //TODO Auto-generated method stubs -          -         //register the required statements for the driver -Class.forName ("Com.microsoft.sqlserver.jdbc.SQLServerDriver"); -Connection con =drivermanager.getconnection (connectionurl); in          -Statement stmt =con.createstatement (); to         //querying the "Sno" column and the "Ssex" column from the "S" table +ResultSet rs = stmt.executequery ("Select Sno,ssex from S"); -          the         //If you find any data, all the output *          while(Rs.next ()) { $System.out.println (rs.getstring ("Sno") + "," +rs.getstring ("Ssex"));Panax Notoginseng         } -     } the  +}

7. Tap the Eclipse's Run button (don't ask the bug, or the play button!!) )

The results of the operation are as follows:

   

If you also see, congratulations, you can directly click on the upper right corner or swipe to the end.

Otherwise, you can also spit out the groove and then turn it down or look down.

Three. Having problems? Problems:

Problem Tip:

TCP/IP connection to host localhost via port 1433 failed. Error: "Connection refused:connect ...

Workaround:

     1, open the SQL Server Management configurator (I believe you will see that all know where to find it, in case you do not know, degrees Niang will speak)

2. Click on the MSSQLSERVER protocol and select the TCP/IP protocol on the right page.

3, right click on the TCP/IP protocol, select "Properties", you need to modify the port address of the connection database

4, jump out of the dialog box, there are many TCP/IP ports, find "IP3", change the IP address for their own computer's IP address (or 127.0.0.1) on the TCP port add 1433, and then click Apply

5, modify the "IPALL" all the ports to "1433" (or this interface, pull down the scroll bar)

         

6. Restart the service

7. Go back to Eclipse and click Run again to see the results of the run.

If your service does not have the right side of the option, you can lose the database installation is incomplete or error, the workaround, not described here.

If the above steps, or the same error message, please check the firewall and other error messages displayed in the other possible error (or seek the help of the surrounding people, in short, do not blame me, haha).

8. The above workaround also applies to databases that cannot log on, and network-related or instance-specific errors occur when establishing a connection to SQL Server

Four. Reference website (dry goods)

For scholars, every use of a new software, learning new technology, their own information on the official website of the document is often the most effective way.

In order to let you understand my problem-solving process, here to post a reference to the question URL:

1. Microsoft JDBC Official website: https://msdn.microsoft.com/en-us/data/aa937724.aspx

2. Microsoft CSDN documentation (using the JDBC driver): https://msdn.microsoft.com/zh-cn/library/ms378526 (v=sql.110). aspx

3. Solve the problem that the database cannot log in and related to the example: http://www.2cto.com/database/201405/300620.html

4. Baidu knows a pair of loaded JDBC, relatively high-quality answer: http://zhidao.baidu.com/link?url= 1lcaee0jxzcbymqoucptkwzcf3-tdhceunzuzdduts2qeqhj6mkndnfrcrbigzoe3wjvupkxut0o4x8vau7yf_

Five. The final statement

The rapid development of technology, software update speed is also very fast, so this article in a few years may not be applicable

Therefore, learn to find the official website to solve the problem is kingly.

This article was written on: November 11, 2015

Link Eclipse and SQL SEVER

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.