开发者

how to share a database to different pc's for a java desktop application?

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 program开发者_C百科ming language and mysql as database. Please help me to do this task...


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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜