【问题标题】:unicode supported jdbc connection with sqlserver using Data source nameunicode 支持 jdbc 与使用数据源名称的 sqlserver 连接
【发布时间】:2012-01-23 10:09:36
【问题描述】:

案例 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 中提交时,如何使用第二种情况(即使用 DSN)插入 Unicode 值。

谢谢..

【问题讨论】:

    标签: java jdbc jdbc-odbc


    【解决方案1】:

    案例 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
    

    【讨论】:

      【解决方案2】:

      尝试这样使用,它对我有用:

      jdbc:sqlserver://190.128.4.195\instanceName:1433;databaseName=unicodedemo;user=ab&password=ab@Admin&useUnicode=true&characterEncoding=UTF-8
      

      【讨论】:

        猜你喜欢
        • 2019-08-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-03
        • 2012-03-04
        • 1970-01-01
        • 1970-01-01
        • 2015-04-24
        相关资源
        最近更新 更多