Link to home
Start Free TrialLog in
Avatar of bhanu_prakash
bhanu_prakash

asked on

Remote Database Connection( using JDBC)

Hi Java programmers,

How do I connect to a remote database( oracle,ms-access)  using Java?

I can connect to local database through JDBC-ODBC bridge.

For local database I use  JDBC-URL  as   jdbc:odbc:mydb.
Here 'mydb' exists on my local machine.

How can I connect  If 'mydb' exists on remote system & I know the IP Address of that system?

Any help is appreciated,

Thanks in Advance,
Bhanu
Avatar of terajiv
terajiv

U can go for RMI in this case
for JdbcOdbc bridge, you must configured LOCAL ODBC datasource name (this can be REMOTE database server - Oracle whatever).

that's ODBC.

but of course - it's better to use some REAL database server + appropriate JDBC driver.
'mydb' that you are talking about can be anywhere in your LAN not only on your local machine.
Avatar of bhanu_prakash

ASKER

Thanks to response,

Can anything like  
jdbc:odbc://remote-hostname:protocol/mydb
works.

Is there any way to work it out without using RMI.

Thanks,
Bhanu
I think what you said (bhanu_prakash) can be done in the way you said. I think I have done it before . =)
But I was using the IP address though.
The connection string was :
jdbc:oracle:thin:@195.164.234.52:8000:ECQ1
This was the oracle connection string I had with ECQ1 as the instance .
> Can anything like  
> jdbc:odbc://remote-hostname:protocol/mydb


NO
ODBC REQUIRES local datasource.

it's ODBC restriction - not a JDBC one
Hi,
Download  the jdbc driver from SUN or the database vendor's site. And in URL mention the IP address of the machine where the database server lies.
Hope this helps
bye
anandshekhar


Vladi21,

---
URL syntax

The "odbc" subprotocol
The "odbc" subprotocol has been reserved for URLs that specify ODBC style Data Source Names.
For this subprotocol we specify a URL syntax that allows arbitrary attribute values to be specified after
the data source name.
The full odbc subprotocol URL syntax is:


jdbc:odbc:<data-source-name>[;<attribute-name>=<attribute-value>]*

Thus valid jdbc:odbc names include:

jdbc:odbc:qeor7

jdbc:odbc:wombat

jdbc:odbc:wombat;CacheSize=20;ExtensionCase=LOWER

jdbc:odbc:qeora;UID=kgh;PWD=fooey

---
if u cannot map drive (its not easy in WAN ) use this solution
:

http://java.sun.com/products/jdbc/faq.html 

How can I use the JDBC API to access a desktop database like Microsoft Access over the network?

Most desktop databases currently require a JDBC solution that uses ODBC underneath.
This is because the vendors of these database products haven't implemented all-Java JDBC drivers.


The best approach is to use a commercial JDBC driver that supports ODBC and the database you want to use.
See the JDBC drivers page for a list of available JDBC drivers.

The JDBC-ODBC bridge from Sun's Java Software does not provide network access to desktop databases by
itself. The JDBC-ODBC bridge loads ODBC as a local DLL, and typical ODBC drivers for desktop databases
Access aren't networked. The JDBC-ODBC bridge can be used together with the RMI-JDBC bridge ,
 however, to access a desktop database like Access over the net. This RMI-JDBC-ODBC solution is free.
http://dyade.inrialpes.fr/mediation/download/ 
If you are using jdbc:odbc then you have to use ODBC DSN configured on you client for that database.Or you can use other vender's direct driver(if it's available for your database) then you can use this url to connect.

jdbc:subprotocol//host:port/database

port depends upon your database

subprotocols depends upon the vender of the driver
If u go for EJB instead of RMI then ur Program will work fine... But for transactions u should provide Login and password... along with IP address...

Try that it will help u more...

Rajiv
ASKER CERTIFIED SOLUTION
Avatar of sergioStateriJr
sergioStateriJr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

The ABove solution required DSN should be present on each client machine...

It is not feasible.

RMI-JDBC Bridge solution is best.
Hi ravindra,
   
    I too prefer RMI-JDBC bridge.Could you please give me some tips in using it. It would be helpful  if  some examples are provided.

Thanks,
Bhanu
ultimatly ur going to my solution....
rt?
RMI ...or EJB...
EJB is actually advance part of RMI
Rajiv
Hi Rajiv,

I don't prefer  to restrict myself to RMI.
But to move for EJB I need more details about it.
Could you help in this way.

Thanks
Bhanu