Hey there,
I am trying to connect Mysql using "mysql-connector-java-5.1.13". I have downloaded it and put it to the lib of a project that i am working on Netbeans. And i found a free host and create and Mysql database. And now i am trying the following code;
import java.sql.*;
public class MysqlConnect
{
public static void main (String[] args)
{
Connection conn = null;
try
{
String userName = "a6990612_jdict";
String password = "0jdict";
String url = "jdbc:mysql://216.108.239.44:3306/a6990612_jdict";
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 */ }
}
}
}
}
But exception catched and it says: Cannot connect to database server.
Is there be a problem with the url, since i am not sure about what will i put there, i put the ip adress of the free host that i am on.
Any idea how can i connect Mysql? Thanks in advance!