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; 

try 

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"); 

finally 

if (conn != null) 

try 

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. 

Or

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.

Or

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. 

Or

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. 

Java Tips

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 © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com 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
www.erpgreat.com or the content authors.