I created a mySQL database on 000webhost and I wanted to connect it into my Java program but somehow driver aren\'t receiving sockets. Here is my code:
Class.for
MySQL from 000webhost doesn't allow you to connect from external applications, just from within pages hosted in their domain.
Please check: How can I connect to MySQL from my computer?
Please remove the table name from the connection string.
just write
Connection conn = DriverManager.getConnection("jdbc:mysql://mysql2.000webhost.com/a4931569_users", username, pass);
JDBC URL Format
The JDBC URL format for MySQL Connector/J is as follows, with items in square brackets ([, ]) being optional:
jdbc:mysql://[host][,failoverhost...][:port]/[database] »
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
If the host name is not specified, it defaults to 127.0.0.1. If the port is not specified, it defaults to 3306, the default port number for MySQL servers.
jdbc:mysql://[host:port],[host:port].../[database] »
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
Here is a sample connection URL:
jdbc:mysql://localhost:3306/sakila?profileSQL=true
Please refer http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html
Edit
In case of
It says: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
you need to go with answer of Math.
MySQL from 000webhost doesn't allow you to connect from external applications, just from within pages hosted in their domain.
Please check: How can I connect to MySQL from my computer?
Please make sure that mysql2.000webhost.com URL allows remote connection for the specified user or not. If it allows then there can be some problem with database driver jar file either its missing or not compatible with database version.
As the javadoc for the DriverManager#getConnection()
method says:
Attempts to establish a connection to the given database URL.
Therefore, remove the Users
table name from the provided URL and it should work.