PDA

View Full Version : java jdbc connection to sql server




ashokformac
Mar 27, 2007, 01:37 AM
Hi , i am new to mac. i am using java jdbc connection to access the data in ms sql server.I am using jTDS jdbc driver and mac 10.4 . I am not able to connect to sql server .
following are the lines i used for connection ..

Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:jtds:sqlserver://172.16.4.59/iarchivev2;user=iarchiveuser;password=system");

but connection was not establishing...
it say unable to connect to remote host..

can any one help me to solve this problem...



lazydog
Mar 27, 2007, 03:23 AM
Hi

Don't you have to call newInstance() on the class?

eg

Class.forName( "com.mysql.jdbc.Driver" ).newInstance() ;

Well that's what I do at any rate.


b e n

ashokformac
Mar 27, 2007, 04:01 AM
hi thank you for your reply,

still it is not working .. the following error occurs

Network error IOException: Operation timed out

can any one help me ?

robbieduncan
Mar 27, 2007, 04:42 AM
Hi

Don't you have to call newInstance() on the class?

eg

Class.forName( "com.mysql.jdbc.Driver" ).newInstance() ;

Well that's what I do at any rate.


b e n

You don't have to call newInstance(). I use JDBC a lot at work connecting to Sybase enterprise database servers. We don't call newInstance(). When you ask for a connection the JDBC libraries automatically create an instance for you if needed. You simply have to ensure that the class has been loaded into the current JVM session. Which is what Class.forName does.

As for why it does not work: did you read and consider the error? It's not apparently a code problem. It is telling you that it did not receive a response from the server specified. Can you ping that IP address?

ashokformac
Mar 27, 2007, 04:58 AM
no i am not able to connect using ping....

lazydog
Mar 27, 2007, 05:04 AM
You don't have to call newInstance(). I use JDBC a lot at work connecting to Sybase enterprise database servers. We don't call newInstance(). When you ask for a connection the JDBC libraries automatically create an instance for you if needed. You simply have to ensure that the class has been loaded into the current JVM session. Which is what Class.forName does.

Thanks for the info… much appreciated!

b e n

robbieduncan
Mar 27, 2007, 05:43 AM
no i am not able to connect using ping....

Well if you can't ping it (this is not connecting, simply sending a packet and seeing if the address replies) then you cannot see that machine at a network level. Either the address does not exist or there are firewalls between you and it that are preventing you from talking to it. Is it a Uni server and you are outside the Uni network perhaps?

ashokformac
Mar 27, 2007, 08:02 AM
thank you very much for your suggestions...