Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / December 2003

Tip: Looking for answers? Try searching our database.

Accessing a Remote Database

Thread view: 
Rhino - 13 Dec 2003 01:24 GMT
I have some Java programs (including applications, applets, and servlets)
that can access the local database just fine. (By "local", I mean that the
application and the database reside on the same PC.)

What do I need to do differently if the database is *not* local? For
example, I have a Windows XP machine and I want programs running on it to
access a MySQL database at my friend's server in another town.

At present, I achieve local access by ensuring that my programs can see the
database driver and then connecting, passing in the URL (e.g.
jdbc:db2:<database-name>), userid, and password.

If I want my programs to run against the database on my friend's Linux box,
what do I need to do? Is it simply a matter of telling the driver to look on
the remote machine instead of my own machine via a different URL or is it
more involved? Can anyone take me through the steps I'll need to take?

Signature

Rhino
---
rhino1 AT sympatico DOT ca
"If you want the best seat in the house, you'll have to move the cat."

Herman Timmermans - 13 Dec 2003 06:23 GMT
> I have some Java programs (including applications, applets, and servlets)
> that can access the local database just fine. (By "local", I mean that the
[quoted text clipped - 13 lines]
> or is it more involved? Can anyone take me through the steps I'll need to
> take?

Hello Rheno,
You use a String URL to pass as a parameter to the getConnection metthod
like this;
Connection getConnection(String URL).
A URL (Uniform Resource Locator) provides a common way of finding resources
on the Internet.  In general the format of a URL is as follows:

<protocol>:<subprotocol>:<subname>

For a jdbc connection, the protocal is always "jdbc".  The subprotocol will
be typically the name of the driver for this specific database connection,
in the case of MySQL, the Connector/J driver requires the subprotocol to be
defined as "mysql".  The subname is a little bit more complex as it defines
the specific information about this connection, i.e; the source of the
database.  It consists of 3 different components in the following general
format:

//<host>[:<port>][/<databasename>]

where host is the domain name or IP address of the server hosting the db.
The port number identiefies the port that accepts the connection, in your
case this will be typically 3306 (defaulted). and of course the final
element is the db name.

Some examples:
jdbc:mysql://192.168.0.2/mydb
jdbc:mysql://linuxserver:4505/myotherdb
jdbc:mysql://friend.company.com/yourfriendsdb

Hope this helps,
Brgds Herman
Signature

Suse Linux Professional 8.1 on Athlon 1.1 Ghz 512 Mb
Anti Spam = remove the "dot" and the "at"
Registered Linux User #264690



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.