Run Java Program Database On Another Computer

How to Run Java Program With Database On Another Computer?
use JBDC.  It doesn't matter where your database. 

import java.sql.*; 

public class Connect 

public static void main (String\[\] args) 

Connection conn = null; 


String userName = "testuser"; 

String password = "testpass"; 

String url = "jdbc:mysql://localhost/test"; 

Class.forName ("com.mysql.jdbc.Driver").newInstance (); 

conn = DriverManager.getConnection (url, userName, password); 

System.out.println ("Database connection established"); 

catch (Exception e) 

System.err.println ("Cannot connect to database server"); 


if (conn != null) 


conn.close (); 

System.out.println ("Database connection terminated"); 

catch (Exception e) { /* ignore close errors */ } 

Just replace localhost with IP address of host where MySql server runs. 
You can do this by using sockets to transfer your query from one computer from other and then execute that query at the other platform.
Install your mysql in remote machine A and setup your JVM in machine B. And try to access the remote database by specifying the IP in the connection url. 

You might also consider configuring your database server to allow remote connections. On some hosts, this feature is disabled by default as a security measure. 

See also
Important Questions To Learn

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of or the content authors.