Eclipse connection to SQL Server 2008 database and summary of issues

Source: Internet
Author: User
Tags microsoft website



Recently, due to reinstall the system, in the installation of various software, the decision to use a blog to record, so that they can view later, also for others reference.



Disclaimer: This blog is not original



Using SQL Server 2008 databases in eclipse



First, prepare the material



To be able to use the database there is a corresponding JDBC, so we will go to the Microsoft website to download:



https://www.microsoft.com/zh-cn/download/details.aspx?id=11774







































II. Configuring SQL Server 2008



Please make sure you have set up the SA, if not, you can refer to the following link to modify:



Http://jingyan.baidu.com/article/8cdccae9452b3c315513cd52.html






























Then restart the database and after the reboot is complete, use the command to test whether port 1433 is open.



Then start menu → Run cmd→ at the command prompt input: telnet 127.0.0.1 1433, (note that there is a space between Telnet and 127, 1 and 1433 have a space) if you are prompted to "cannot open a connection to the host, port 1433: Connection Failed", Indicates that port 1433 is not open and needs to be re-configured. If the display Telnet is not an internal command, follow the steps in the figure below to set it, if the connection is successful, display 8:






Open the Control Panel, enter the program, then click Open or Close windows, pull down, you can see the Telnet client, select. Then repeat the fifth step above. http://jingyan.baidu.com/article/6525d4b1377913ac7d2e94eb.html






Configure the environment variable classpath, place the SQLJDBC4 in jdk1.7 (your version) Lib, http://jingyan.baidu.com/article/cbcede07cf5fef02f40b4ddd.html



This is a setup link for environment variables.









Right-click on the computer's properties and click Advanced Properties Settings, click Environment variable settings, add the jar to the previously installed directory, and if not, create a new, and set the address directory for it.






Third, use the Eclipse test to link the SQL Server 2008 database:



1. Open the SQL Server 2008 database and create a new database JSP.



2. Run eclipse to create a new project, and then create a new package with a new Java file in the package, the main file.









3. Sqljdbc4.jar copy into the project, then right click on it and click Build Path. (You can also put the Sqljdbc4jar class under the Jre/lib/ext, and put it under Tomcat/lib, so that it can be applied to all JSP files, reducing the loading of Sqljdbc4jar for each project)



4, enter the Main.java, copy the following code into





1 package pkg;
  2 
  3 import java.sql.*;
  4
  5 public class Main {
  6 public static void main(String [] args)
  7 {
  8 String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
  9 String dbURL="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=jsp";
10 String userName="sa";
11 String userPwd="123";
12 try
13 {
14 Class.forName(driverName);
15 System.out.println("Loading Driver Success!");
16 }catch(Exception e){
17 e.printStackTrace();
18 System.out.println("Load driver failed!");
19 }
20 try{
21 Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
22 System.out.println("Connecting the database successfully!");
23 }catch(Exception e)
twenty four {
25 e.printStackTrace();
26 System.out.print("SQL Server Connection Failed!");
27 }
28 }
29
30 } 


If there is talnet 127.0.0.1 post 1433 no response in the connection process, first check whether the settings are wrong, if not, then restart the computer, because it may not be updated, I also encountered this problem, and then successfully connected to the database after reboot.



Reference link http://blog.163.com/jackie_howe/blog/static/19949134720125173539380/



Eclipse connection to SQL Server 2008 database and summary of issues


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.