2012-01-23 22 views
2

案例1:我試圖連接到SQLSERVER這是坐落使用統一使用數據源名稱與支持SQLSERVER的JDBC連接

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
     connection = DriverManager.getConnection("jdbc:sqlserver://190.128.4.195/unicodedemo?user=ab&[email protected]&useUnicode=true&characterEncoding=UTF-8"); 

當我執行遠程服務器上的2005數據庫,我得到了以下異常:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 190.128.4.195/unicodedemo?user=ab&[email protected]&useUnicode=true&characterEncoding=UTF-8, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.". 

案例2:但是當我試着用用

數據源名稱
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ; 
connection = java.sql.DriverManager.getConnection("jdbc:odbc:unidemo","ab","[email protected]"); 

數據成功插入,但在這種情況下,它沒有顯示插入的Unicode數據。其顯示爲?????

任何人都可以幫助解決錯誤?當我在案例1中提交時,如何使用第二種情況(即使用DSN)插入Unicode值。

謝謝..

回答

2

案例1: URL連接到SQL Server的格式是這樣的:

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

這意味着你應該改變你的連接網址

jdbc:sqlserver://190.128.4.195;databaseName=unicodedemo;user=ab;[email protected];useUnicode=true;characterEncoding=UTF-8 
相關問題