• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using IP address how to get connection to server in JDBC

 
Nitin Jawarkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have any JDBC connection code which access the local database SQL Server but now i want to connect to my web server and want to access database on same. So should i give IP address and datasource name or any other plz tell, if possible plz give one example code in JDBC

Thanx...
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitin,
When you type the connection string on your local machine, you currently have "localhost." You can replace this with an IP address.
 
Nitin Jawarkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

can u give me this solution with one example.....Plz

:roll:
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nitin Jawarkar:
hello,

can u give me this solution with one example.....Plz

:roll:


Nomally i create a Datasource in my AppServer , that datasource has the connection to the Database.Then i used to look up the data soure in order to get a connection. Is this way of getting connected to the remote db is good.
 
Nitin Jawarkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

but how my JDBC code find out the datasource on remote machine,
using IP address or any other technique, and also i m using JTDS 0.9
driver for connection so is it compalsary to set class path for that
if yes then where should put that jar file in jdk. Error is like this

Connection Error:java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.DriverConnection
 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope this statement would help you out.
I am using postgresql database therefore
Conn = DriverManager.getConnection("jdbc ostgresql://192.168.0.10:2222/masterdb","user_name","pwd");
 
Nitin Jawarkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Thanx for giving the suggetion but i m using JTDS driver for connection so where should i put my .jar file to get result becoz right now it gives me classnotfoundexception and driver name, currently i put .jar file in /lib and /jre/lib also.
Thanx
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put it on the classpath of the application that connects to the DB...


or put it in JRE/lib/ext (i would not do this because it requires an installaion step more if you distribute your app and also because your DB app is probably the only one to use that jar file)


pascal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic