Connect Java remotely to MYSQL DB on another network

how to access mysql database from another computer using java
mysql allow remote connections windows
mysql connect to remote database
connect to mysql database
connectivity to remote database in java
how to connect remote mysql database in java using eclipse
connectivity to remote database in jdbc
how to share mysql database

I want to write a java application that uses a mysql database to store and retrieve information. I am still just a beginner and I do not have a lot of knowledge on web hosting providers and server architecture. In this application, several clients will have to access this remote database located on a server machine maybe.

Currently, I can connect to the database from the same computer that runs the mysql server (I am using workbench by the way). Any suggestions on what should I do?

public static Connection openDatabase()
{ 
    Connection myConn;
    try {

      myConn = 
            DriverManager.getConnection(Configs.getProperty("DatabaseURL"));

     return myConn;
   } catch (SQLException e) {

      e.printStackTrace();
   }

   return null;
}

The url is:

jdbc:mysql://Atomic-PC:3306/test?autoReconnect=true&rewriteBatchedStatements=true&useSSL=false&user=root&password=password

If you are trying to connect to remote database then yo need to change the database url from localhost to remote server ip address.

jdbc:mysql://Atomic-PC:3306/test

to

jdbc:mysql://<db-server-ip-address>:<db-server-port>/<db-name>

Assuming, remote server ip address is 10.234.05.123 and database port number is 3300 and database name is remoteDB. Then,

jdbc:mysql://10.234.05.123:3300/remoteDB

Connect remotely to a MySQL database in my Linux Hosting , How do I connect to a MySQL database from another server? Content updated daily for mysql online database. Get reliable information in seconds. Search Teoma today!

First of all you have to find connection URL, port and credential from MySql workbench you are using. If hosting provider provides a public IP for DB server you should be able to access it from anywhere by using following code in Java.

import java.sql.Connection;
import java.sql.DriverManager;

public class Main {
  public static void main(String[] argv) throws Exception {
    String driver = "com.mysql.jdbc.Driver";
    String connection = "jdbc:mysql://localhost:3306/YourDBName";
    String user = "root";
    String password = "root";
    Class.forName(driver);
    Connection con = DriverManager.getConnection(connection, user, password);
    if (!con.isClosed()) {
      con.close();
    }
  }
}

For this reason you have to import mysql connection driver to your application first.

Java Database Connectivity with MySQL, Currently, I can connect to the database from the same computer that runs the mysql server (I am using workbench by the way). Any suggestions on what should  First of all you have to find connection URL, port and credential from MySql workbench you are using. If hosting provider provides a public IP for DB server you should be able to access it from anywhere by using following code in Java.

your web hosting company should be able to provide you with the url:port which you can use in your connection string to connect to MySQL(or any other remote db for that matter)

Connecting to Remote DB using JDBC, Connection Time Out, Connecting to Remote DB using JDBC, Connection Time Out I am fairly new to mysql and networking but I know my way around for the most part. Java App code is below and the stack trace is posted below that. by Oracle and does not necessarily represent the opinion of Oracle or any other party. How to Connect Java Program to Remote Server/Online Database or another part of the world. Also called a remote computer or remote host. How to connect to remote MySql database from

MySQL :: Connecting a Java Desktop Application to Remote MySQL , I am writing a Java application to access values in a remote MySQL instance. Everything I have read about connecting to the DB has been using will be on the same network when queries will be tested from the Java application. does not necessarily represent the opinion of Oracle or any other party. Connect to remote MySql database using Command Prompt - Duration: 8:44. jinu jawad m 12,024 views

How To Setup Remote Database Connection, Allowing a Remote Server to Access Your Database. Before connecting to MySQL from another computer, the connecting computer must be enabled as an​  mysql> GRANT ALL ON fooDatabase.* TO fooUser@'1.2.3.4' IDENTIFIED BY 'my_password'; This statement grants ALL permissions to the new user when the user connects from the specified IP address by using the specified password. Test the connection remotely. To test the connection remotely, access the MySQL server from another Linux® server.

How to connect to remote MySql database from NetBeans, How to connect to remote MySql database from NetBeans. jinu jawad m This project shows Duration: 12:01 Posted: Jun 19, 2017 database_name is the name of the database that the user will connect to. user_name is the name od the MySQL user. ip_address is the IP address from which the user will connect.

Comments
  • Add your db connecting code, so we can provide you in depth answer
  • @ChathuraBuddhika, I had added my code so far
  • Hello, thanks for the help. I am using mysql as my rdbms. I manage my database manually through mysql workbench on my local machine. How can I get the ip address of my db? Would I be able to access the db from another network?
  • @MariaGonzalez You need ip-address of server where you have installed mysql database.
  • Thanks for the help! Do you know how can I get a hostname that is visible to clients in other networks?
  • You can use Query SELECT USER(); to get username and hostname. It will return like username@hostname
  • What web hosting companies would you recommend? Which plan should I get?
  • There are sooo many of them..just do a google search for best web hosting companies..All you need to make sure they provide you with MySQL server to connect to.