views:

37

answers:

4

Hi experts,

I am making an application which have to be used in different pc's, and it has to share the same database. I have no idea how to do it. I am using the java as programming language and mysql as database. Please help me to do this task...

+3  A: 

Use JDBC and connect all your app to one MySql DB Server

org.life.java
A: 

On server-side you should create user which will be granted privileges to access your database from different foreign hosts:

GRANT ALL ON *.* TO 'someuser'@'somehost';

Read more here: http://dev.mysql.com/doc/refman/4.1/en/grant.html

On client-side you should configure database connection to use host where your database is installed. Read JDBC API reference for details.

Kel
A: 

Does a client-server model not work for you? If you have somewhere to host a server the normal method accomplishing something like this is to encapsulate your database behind the server and all clients connect to your server to exchange information.

You have a variety of options for communicating between the clients and the server:

Your server could be a simple web app where your clients all make URL calls to the server to accomplish various tasks. Implementing REST or SOAP would make the calls even easier if you're doing anything non-trivial.

RMI if your not going over the internet makes things really easy (you can get the basics of RMI in a few hours of reading).

Assuming you have the network connectivity, you can also just have each client make their own connection directly to the database. But only do this if you are on a safe intranet only.

David Parks
Thanks for your quick reply sir, i'll try the rmi and let you know everything...
Ryan
+1  A: 

The way to talk to a database in Java is JDBC.

See http://download.oracle.com/javase/tutorial/jdbc/index.html for a good tutorial on how to use it.

Thorbjørn Ravn Andersen