2

ケース 1:リモート サーバー上にある sql-server 2005 データベースに接続しようとしています。

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

実行すると、次の例外が発生しました。

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 190.128.4.195/unicodedemo?user=ab&password=ab@Admin&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","ab@Admin");

データは正常に挿入されましたが、その場合、挿入された Unicode データが表示されませんでした。として表示され?????ます。

誰でもエラーの解決を手伝ってもらえますか? ケース 1 でコミットしている場合、2 番目のケース (DSN を使用) を使用して Unicode 値を挿入するにはどうすればよいですか。

ありがとう..

4

2 に答える 2

3

ケース 1: SQL Server への接続 URL の形式は次のとおりです。

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

これは、接続 URL を次のように変更する必要があることを意味します。

jdbc:sqlserver://190.128.4.195;databaseName=unicodedemo;user=ab;password=ab@Admin;useUnicode=true;characterEncoding=UTF-8
于 2014-01-14T21:59:45.380 に答える