繁体   English   中英

连接到sql server时端口号不正确

[英]Port number is not correct while connecting to sql server

我试图从Netbeans连接到SQL Server,如下所示。 我在我的Libraries forlder项目中有sqljdbc4.jar。

try{
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    connRemoteforGlobal = java.sql.DriverManager.getConnection("jdbc:sqlserver://xx.xx.x.xxx:1433/test",RemoteSQLServerUser,RemoteSQLServerPass);

    if(connRemoteforGlobal != null)
    {
        System.out.println("Connection Successful !");
    }
}
catch(SQLException ex2){
    ex2.printStackTrace();
    System.out.println("Error Trace in Connection : " + ex2.getMessage());
}

并收到以下错误:

netbeans或我的连接中是否还需要其他设置? 端口号?

Error Trace in Connection : The port number 1433/test is not valid.
com.microsoft.sqlserver.jdbc.SQLServerException: The port number 1433/test is not valid.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:691)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at mypackage.myclass.call(myclass.java:408)
    at mypackage.myclass.call(myclass.java:25)
    at javafx.concurrent.Task$TaskCallable.call(Task.java:1259)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

它应该是:

jdbc:sqlserver://xx.xx.x.xxx:1433;databaseName=Test

这是格式:

jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]

http://technet.microsoft.com/en-us/library/ms378428.aspx

查看http://technet.microsoft.com/en-us/library/ms378988.aspx了解属性。 无论如何,1433似乎是默认的端口号,因此没有必要指定它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM