0

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 ?

Praba
  • 1,373
  • 10
  • 30
AZT
  • 149
  • 1
  • 13
  • This may be due to your system is not permitted for accessing remote mysql DB see [this](http://stackoverflow.com/a/23604182/2664200) – SpringLearner Sep 17 '14 at 11:32
  • Can you ping `mysql11.000webhost.com` and if so, can you telnet to the default mysql port in that box? (rarely, ping will work but telnet will be disabled and very rarely, both will be disabled - but it's worth a check). And I believe, you should be wondering 'what can be the problem' :) – Praba Sep 17 '14 at 11:43
  • no i cant ping that it says request timeout. Now what I must do ?? – AZT Sep 17 '14 at 11:45
  • If you have a network team, talk to them to see if there is any firewall (either in your system/network/database system) or a VPN rule (if you're in VPN) blocking access to the host and the port. Unless you can access the box, you can't connect to it via your code as well. – Praba Sep 17 '14 at 11:49
  • Do you know any other free database hosting without that problem so that I can test my app – AZT Sep 17 '14 at 11:50
  • Is your online MySQL service accessible using URL, Username and password you used from elsewhere? You can test that using Workbench. Your JDBC connection URL doesn't seem to have port number in it. – Sridhar Sep 17 '14 at 12:03

1 Answers1

0

I have gone through all the comments above and found that 000host.com doesn't provide the facility that its database can get accessed by outside its own space. So with little googling i found http://www.db4free.net that provide free mySql database for testing purpose. And in this way my problem get solved. Thanks to all comentators.

AZT
  • 149
  • 1
  • 13