Code: Select all
import java.sql.*;
class Connect
{
public static void main(String args[])
{
Connection conn = null;
try
{
String userName = "username";
String password = "password";
String url = "jdbc:mysql://host/database";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.out.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 */ }
}
}
}
}
I'm not sure if the problem is related to my program or my server, if anyone can offer suggestions. I installed libmysql-java, incase that made any difference.