2

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..

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
Nishit Jain
  • 1,549
  • 8
  • 21
  • 33

2 Answers2

4

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
Kamil Roman
  • 973
  • 5
  • 15
  • 30
0

Try using like this, it worked for me:

jdbc:sqlserver://190.128.4.195\instanceName:1433;databaseName=unicodedemo;user=ab&password=ab@Admin&useUnicode=true&characterEncoding=UTF-8
Sikandar Sahab
  • 638
  • 3
  • 10
  • 27