Solved

Remote Database Connection( using JDBC)

Posted on 2000-04-14
15
265 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:bhanu_prakash
  • 3
  • 3
  • 2
  • +6
15 Comments
 
LVL 3

Expert Comment

by:terajiv
ID: 2715234
U can go for RMI in this case
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 2715541
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.
0
 
LVL 3

Expert Comment

by:ovidiucraciun
ID: 2715546
'mydb' that you are talking about can be anywhere in your LAN not only on your local machine.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:bhanu_prakash
ID: 2715634
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
0
 
LVL 1

Expert Comment

by:computerpunk
ID: 2715677
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 .
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 2715736
> Can anything like  
> jdbc:odbc://remote-hostname:protocol/mydb


NO
ODBC REQUIRES local datasource.

it's ODBC restriction - not a JDBC one
0
 

Expert Comment

by:anandshekhar
ID: 2716122
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
0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2718568


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/ 
0
 
LVL 2

Expert Comment

by:anand29
ID: 2718702
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
0
 
LVL 3

Expert Comment

by:terajiv
ID: 2718860
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
0
 

Accepted Solution

by:
sergioStateriJr earned 50 total points
ID: 2735090
Here´s a sample to connect a SQL Server using JDBC:ODBC Bridge driver :

// This sample uses a ODBC connection Intranet_Teste
import java.sql.*;

public class Teste  {
  public static void main(String args[]) throws ClassNotFoundException, SQLException {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Carrega o Driver JDBC/ODBC
    String url = "jdbc:odbc:Intranet_Teste"; // JDBC/ODBC Connection String

    Connection connIntranet = DriverManager.getConnection(url,"sergio","1221321"); // Do The Connection

    Statement stmt = connIntranet.createStatement(); // Create the object that will be the Statement

    // Execute the Stament (Insert, Create Table, ...)
    stmt.executeUpdate("Insert into Tecnicos_SSUP(Tecnico_Code, Tecnico_Name, Tecnico_Login," +
      " Tecnico_Lotacion, Tecnico_Email, Tecnico_Enable) Values(999, 'Test Name', 'TestLogin'," +
      "'TestLotacion', 'teste@teste.com.br', 1)");

    // Execute a Query (SELECT, Update)
    ResultSet rsTecnicos = stmt.executeQuery("Select * from Tecnicos_SSUP Order by Tecnico_Code");

    // Run the Stament (until eof)
    while (rsTecnicos.next())  {
      int iCodigo  = rsTecnicos.getInt("Tecnico_Code");
      String sNome = rsTecnicos.getString("Tecnico_Name");
      System.out.println(iCodigo + " - " + sNome);
    }

    // Closes the JDBC/ODBC Connection
    connIntranet.close();
  }
}
0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2738463

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

It is not feasible.

RMI-JDBC Bridge solution is best.
0
 

Author Comment

by:bhanu_prakash
ID: 2739479
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
0
 
LVL 3

Expert Comment

by:terajiv
ID: 2741461
ultimatly ur going to my solution....
rt?
RMI ...or EJB...
EJB is actually advance part of RMI
Rajiv
0
 

Author Comment

by:bhanu_prakash
ID: 2743081
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
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 95
Java Server Faces parameter pass? 6 47
web application structure 18 76
runtime exception 2 27
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now