Java JDBC SQL Server 2012 database connection

Reference:
https://www.cnblogs.com/cjwxf/p/6138416.html
first ensure that the SQL Server 2012 is installed with SQL Server Authentication
First, because the SQL Server 2012 installed, the default protocol is not open, so to open the SQL Server configuration Manager, open:
1, installed after SQL Server 2012, start of operation → Microsoft SQL Server 2012 → SQL Server configuration Manager, shown in Figure 1:

figure 1
2, open the window as shown in FIG. In the "[your database name] agreement", select it, you can see right column, are set to "Enabled"
Map
3. Double-click the TCP / IP (right → Properties), the pop-up window, select "IP Address" tab, IP1 and IP10 of [IP address] is set to 127.0.0.1, and all [of IPx] [enabled] to Yes. Then, drag the pull-down bar to the bottom, the IPAll the [TCP port] is set to [1433], remaining unchanged. As shown in Figures 3 and 4:

image 3

Figure 4
4. Restart the computer.
5. Next, using the telnet command to test whether the number of open end 1433. First, to ensure the telnet service is turned on. Open win 10 telnet methods:
(a) open the control panel

Here Insert Picture Description
(B) Open the Programs and Features

Here Insert Picture Description
(C) function to enable or disable windows

Here Insert Picture Description
Here Insert Picture Description
(Iv) ok, then CMD enter: telnet 127.0.0.1 1433
if prompted "Can not open connection to the host, on port 1433: Connect failed", then the 1433 port is not open, need to re-configure or more.

6. Configure CLASSPATH environment variables
to download SQL Server JDBC Driver
Double-click the CLASSPATH variable (or after check CLASSPATH → editor), appended to the final surface "in the system variable; D: \ SQL Server \ sqljdpc drivers \ sqljdbc_6.0 \ chs \ jre8.sqljdbc42.jar "NOTE: in front of a; separator
Here Insert Picture Description
7. sqljdbc42.jar library file copy to D: \ jdk 8 \ jre \ lib \ ext directory under
(that is downloaded JDBC driver inside the jar ext copy of the current packet using the directory lib directory jre directory JDK)
8. the tests:
(a) creating TestDB open SQL Server database
Here Insert Picture Description
(B) in the open Eclipse new project JDBCTest New class Testjdbc
Here Insert Picture Description
(c) code is as follows
Here Insert Picture Description
Here Insert Picture Description
(iv) Once created you can see in the new SQL Server table in
Here Insert Picture Description
java development after ResultSet how close the result set, but also the use of database data:
https://blog.csdn.net/Krishnna/article/details/52973388

Released six original articles · won praise 0 · Views 107

Guess you like

Origin blog.csdn.net/Blackswan31/article/details/90301725