This is the 22nd day of my participation in the August More Text Challenge

Please ensure that have been set up sa, if not, you can refer to the following link to modify jingyan.baidu.com/article/8cd…

 

 

 

 

 

 

 

 

 

Then restart the database. After the restart, use the command to test whether port 1433 is open.

Start menu → Run CMD → Enter Telnet 127.0.0.1 1433 at the command prompt: Telnet 127.0.0.1 1433, (note that there is space between Telnet 127 and 1 and 1433) If the connection fails, port 1433 is not enabled. You need to configure port 1433 again. If Telnet is displayed instead of an internal command, set it according to the steps following the figure. If the connection is successful, as shown in Figure 8 will be displayed:

 

Open the control panel, enter the program, and then click on Open or Close Windows. Pull down to see the Telnet client. Then repeat step 5 above. Jingyan.baidu.com/article/652…

 

Configure the classpath environment variable, place the sqljdbc4 in jdk1.7 (your version) in the lib, jingyan.baidu.com/article/cbc…

This is a link for setting environment variables.

 

 

Right-click your computer’s properties, then click Advanced Properties Settings, click Environment Variable Settings, and add the JAR to the directory you installed previously. If not, create a new jar and set the address directory for it.

 

SQL Server 2008 SQL Server 2008

1, open SQL Server 2008 database, create a database JSP.

2. Run Eclipse and create a new project, and then create a new package. Inside the package, create a Java file, Main file.

 

 

3. Copy sqljdbc4. Jar into the project, then right click on it and click Build Path. (You can also put the SQLJdbc4JAR class in jre/lib/ext and tomcat/lib, so that it can be applied to all JSP files, reducing the sqlJdbc4JAR load for each project)

4. Go to main.java and copy the following code

package pkg;

import java.sql.*;


public class Main {
    public static void main(String[] args) {
        String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        String dbURL = "JDBC: essentially: / / 127.0.0.1:1433; DatabaseName=jsp";
        String userName = "sa";
        String userPwd = "123";

        try {
            Class.forName(driverName);
            System.out.println("Driver loaded successfully!");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Driver load failed!");
        }

        try {
            Connection dbConn = DriverManager.getConnection(dbURL, userName,
                    userPwd);
            System.out.println("Database connection successful!");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.print(SQL Server connection failed!); }}}Copy the code

If talnet 127.0.0.1 POST 1433 no response is displayed during the connection process, check whether the setting is correct. If not, restart the computer, because it may not be updated. I also encountered this problem, and then restart the database successfully.