The following is transferred from: https://www.cnblogs.com/skylarzhan/p/7619977.html
Using SQL Server 2008 databases in eclipse
First, prepare the material
To be able to use the database, we have to have JDBC, so we're going to download https://www.microsoft.com/zh-cn/download/details.aspx?id=11774 on the Microsoft website.
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
1Import java.sql.*;2 3 Public classMain {4 Public Static voidmain (String [] args)5 {6String drivername="Com.microsoft.sqlserver.jdbc.SQLServerDriver";7String dburl="jdbc:sqlserver://127.0.0.1:1433;databasename=management";//here Databasename= the name of the database you created yourself .8String username="SA";//Default Account9String userpwd="052214";//This is my own password, if the installation is not set password, the general default is empty or 123Ten Try One { A Class.forName (drivername); -System. out. println ("Load Driver Success! "); -}Catch(Exception e) { the e.printstacktrace (); -System. out. println ("Load driver failed! "); - } - Try{ +Connection dbconn=drivermanager.getconnection (dburl,username,userpwd); -System. out. println ("Connect to the database successfully! "); +}Catch(Exception e) A { at e.printstacktrace (); -System. out. Print ("SQL Server Connection failed! "); - } - } - -}
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/
A few questions about the Eclipse connection to SQL Server 2008