本文介绍了使用数据源名称与sqlserver的unicode支持的jdbc连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况1:我正在尝试使用

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");

执行时,出现以下异常:

When I execute, I got the following exception :

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数据.其显示为?????.

Data successfully gets inserted but in that case it was not showing the Unicode data inserted. Its showing as ?????.

有人可以帮助解决错误吗?在案例1中提交时,如何使用第二种情况(即使用DSN)插入Unicode值.

Can anybody help in solving the error? When I am committing in Case 1, how can I insert Unicode values using the second case (i.e using DSN).

谢谢..

推荐答案

案例1:与SQL Server的连接URL的格式为:

Case 1:The format of connection URL to SQL Server is this:

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

这意味着您可能应该将连接URL更改为

which means that you should probably change your connection URL to

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

这篇关于使用数据源名称与sqlserver的unicode支持的jdbc连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 10:20
查看更多