I am trying to fetch data from my Online database, but following error is coming. However it is working fine for my local database.
Java Code
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.sql.*;
import javax.swing.JOptionPane;
public class BankingSystem extends JFrame {
public static void main(String[] args) throws Exception
{
int ur=0;
int PIN;
String ID;
int userSelection=0;
Boolean pinCorrect = false;
int amountDeposite;
int amountWithdraw;
int updateResult;
Boolean isExit=false;
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://mysql11.000webhost.com/a46854323_javaapp";
String user = "a46854323_javaapp";
String pass="password";
Connection con = DriverManager.getConnection(url,user,pass);
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
}
and I get the following error:
`
Exception in thread "main" java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.SocketException: java.net.ConnectException: Connection timed out: connect
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection timed out: connect
STACKTRACE:
java.net.SocketException: java.net.ConnectException: Connection timed out: connect at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:143)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1805)
at com.mysql.jdbc.Connection.<init>(Connection.java:452)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at BankingSystem.main(BankingSystem.java:22)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1875)
at com.mysql.jdbc.Connection.<init>(Connection.java:452)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at BankingSystem.main(BankingSystem.java:22)
What can be the solution ?