I'm trying to connect to a remote SQL database that I can access via web through http://smart.ihu.edu.gr/phpmyadmin/. The database inside that is awesomedb/pwndoes'
. That's where the tables that I want to use are.
The thing is, I'm completely new to Database/mySQL connectivity in applications and even though I've tried working through the examples posted here: Connect Java to a MySQL database I've been unable to connect to the DB yet.
Here's my code:
package thesistest;
import java.sql.*;
public class ThesisTest {
public static void main(String[] args)
{
//-------------------------------------
// JDBC driver initialisation
//-------------------------------------
try
{
System.out.println("Loading driver...");
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver loaded!");
}
catch(ClassNotFoundException e)
{
throw new RuntimeException("Cannot find the driver in the classpath!", e);
}
//-------------------------------------
// Driver loaded, let's try establishing a connection.
//-------------------------------------
String url = "jdbc:mysql://smart.ihu.edu.gr/phpmyadmin/awesomedb/pwnodes";
String username = "root";
String password = "[redacted]";
Connection connection = null;
try
{
System.out.println("Connecting database...");
connection = DriverManager.getConnection(url, username, password);
System.out.println("Database connected!");
}
catch (SQLException e)
{
throw new RuntimeException("Cannot connect the database!", e);
}
finally
{
System.out.println("Closing the connection.");
if (connection != null) try { connection.close(); } catch (SQLException ignore) {}
}
} //end of main
} //end of class ThesisTest
I'm convinced that the URL I'm typing in is wrong. Note that the database is remote and I do not have an instance of any mySQL software running on my machine. Is it possible to just connect a simple java app with a remote DB this way?
Note 2: I have tried putting :3306 at the end of the smart.ihu.edu.gr link, to no avail. Thanks for the headsup, @NickJ
By the way, here's the result of the build+run:
(Full resolution here: https://i.stack.imgur.com/etHVv.png)