0

我最近尝试使用 JDBC 驱动程序配置 MS SQLServer,我已经安装了 SQL SERVER EXPRESS edition 2016 和 JDBC DRIVER 4(sqljdbc 4.0)。为了我自己的测试目的从网络修改和运行示例代码后,我得到了这个错误

com.microsoft.sqlserver.jdbc.SQLServerException: The server sqlexpress is not configured to listen with TCP/IP.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(SQLServerConnection.java:3603)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.primaryPermissionCheck(SQLServerConnection.java:1225)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:972)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at JdbcTest.main(JdbcTest.java:24) 

I have taken these step for the solution
1.I have disabled firewall
2.Enable TCP/IP for SQLSERVER(SQLEXPRESS) from configuration manager
3.I have given port number 1434
4.Enabled SQL Browser Services

但是代码没有编译。这是我的代码:

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JdbcTest {





    public static void main (String[]args)

    {   

        Connection con=null;
        try{
            String dbURL = "jdbc:sqlserver://localhost\\SQLEXPRESS;user=codemen;password=";

            //String user="codemen";
            //String password="cd";
            //DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());

            con=DriverManager.getConnection(dbURL);
            if(con!=null)
            {
                DatabaseMetaData dm=(DatabaseMetaData)con.getMetaData();
                System.out.println("Driver name: "+" " +dm.getDriverName());
                System.out.println("Driver version :" +" "+ dm.getDriverVersion());
                System.out.println("Product name: " + dm.getDatabaseProductName());
                System.out.println("Product version: " + dm.getDatabaseProductVersion());

            }

        }
        catch(SQLException ex)
        {
            ex.printStackTrace();

        }
        finally
        {
            try{
                if (con !=null && !con.isClosed())
                {
                   con.close(); 
                }
            }
            catch(SQLException sq)
            {
                sq.printStackTrace();
            }
        }
    }

}

如果我有一个克服这个问题的指南,那将是很大的帮助。提前致谢

4

0 回答 0