unicode supported jdbc connection with sqlserver using Data source name
12,950
Case 1: The format of connection URL to SQL Server is this:
jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
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
Author by
Nishit Jain
Updated on June 04, 2022Comments
-
Nishit Jain almost 2 years
Case 1: I am trying to connect to the sql-server 2005 database which is situated on the remote server using
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.".
Case 2: But when I tried using Data source name using
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ; connection = java.sql.DriverManager.getConnection("jdbc:odbc:unidemo","ab","ab@Admin");
Data successfully gets inserted but in that case it was not showing the Unicode data inserted. Its showing as
?????
.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).
Thanks..