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

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.