jdbc 连接 sqlServer

代码 :public class ConToHisDataBase {
                 private Connection con;
                 private CallableStatement cs;
                 private ResultSet rs;
       
                 public void getConnection() {
                    try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("加载驱动成功!");
String url = "jdbc:sqlserver://192.168.127.4:5100;DatabaseName=HISDATA";
con = DriverManager.getConnection(url,"YHUSER","YHUSER");
System.out.println("连接成功!");
 } catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();

}

                }

       }

控制台输出 :

加载驱动成功!
六月 30, 2017 3:39:37 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: c4fea525-8b9e-4a77-ab28-f5f1b6cef1fb Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:38 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 22725f1e-bf77-4e97-a12e-1aa8338edd45 Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:38 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 1a9d197b-55c8-4c2e-9656-2ec43d358b6d Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:38 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 6996dcad-b0ad-4736-b1be-59e6945d07dd Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:39 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: b7ae4402-7cb2-468d-bc7f-0ee7817ad5c6 Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:40 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 3427c743-42d9-48f4-89bc-49d55e87b9c8 Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:41 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 9248a8d4-0e6d-4c88-ad26-7172c73e0550 Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:42 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: b5754bc9-e08b-4a86-a5aa-65d6afd8584f Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:43 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 6959a164-530b-4425-83ab-ba3fc115e9c1 Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:44 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: f24b1d62-1acb-44e4-b0f6-55f984968092 Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:45 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: e8dc9282-4bd2-47f4-a232-ec4dd823617d Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:46 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: b013691b-8d14-4484-bf30-05e1cb1235f3 Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:47 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: cfa1faea-8083-4cd3-a13b-1ce51809bb55 Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:48 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 8cd5df19-8480-46a2-9c75-4d0d2f3b44f6 Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:50 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 8469a7b1-1636-43bd-a136-50f31e5f399c Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:51 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 50dc2810-5239-49da-9c1b-564dcfdebe81 Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
六月 30, 2017 3:39:52 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 ClientConnectionId: 168c57b4-a298-4513-947c-50a420a001af Prelogin error: host 192.168.127.4 port 5100 Unexpected response type:0
com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 5100 连接到主机 192.168.127.4 的 TCP/IP 连接失败。错误:“驱动程序收到意外的登录前响应。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接。该驱动程序只能与 SQL Server 2000 或更高版本一起使用。”。 ClientConnectionId:168c57b4-a298-4513-947c-50a420a001af
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2400)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2384)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(SQLServerConnection.java:2177)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1973)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1628)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:773)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1168)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.hiepsoft.base.ConToHisDataBase.getConnection(ConToHisDataBase.java:19)
at com.hiepsoft.base.ConToHisDataBase.useHisDeptProcedure(ConToHisDataBase.java:29)
at com.hiepsoft.dao.his.Procedure.getHisDeptList(Procedure.java:19)
at com.hiepsoft.rest.ewell.esb.test.main(test.java:74)
Exception in thread "main" java.lang.NullPointerException
at com.hiepsoft.base.ConToHisDataBase.useHisDeptProcedure(ConToHisDataBase.java:31)
at com.hiepsoft.dao.his.Procedure.getHisDeptList(Procedure.java:19)
at com.hiepsoft.rest.ewell.esb.test.main(test.java:74)

你可能感兴趣的:(jdbc 连接 sqlServer)