Java connection to mysql

Woohoo, after two typos and an unnecessary ticket to hostgator support I managed to make a connection to a mysql server (@hostgator) with Java.

Click more to see the code.

package org.connect;
import java.sql.*;
public class TestConnect {
public static void main(String[] args)
{
Connection conn = null;
try
{
String userName = “mordy3_test”;
String password = “test”;
String url = “jdbc:mysql://harrisburgvolleyball.com:3306/mordy3_test”;
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 */ }
}
}
}
}

package org.connect;

import java.sql.*;

public class TestConnect {

public static void main(String[] args)

{

Connection conn = null;

try

{

String userName = “mordy3_test”;

String password = “test”;

String url = “jdbc:mysql://harrisburgvolleyball.com:3306/mordy3_test”;

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 */ }

}

}

}

}