• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using IP address how to get connection to server in JDBC

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

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

:roll:
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 158
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic