I just installed mySql and apprently when trying to
test it with a standalone application I get an error.
the problem is here:
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
String url = "jdbc:mysql://localhost/test";
What is missing? I tried somthing like:
String url = "jdbc:mysql://localhost:3306/test";
and other...but nothing works
username/password is fine. I can build tables on test with MySQLCC
any idea?
my code is this:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Test3
{
public static void main(String[] args)
{
Connection conn = null;
//open connection to db
try{
String userName = "root";
String password = "letmein";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
String url = "jdbc:mysql://localhost/test";
conn = DriverManager.getConnection (url, userName, password);
System.out.println("Database connection established");
}catch(SQLException sqlex)
{
System.out.println("SQL EXCEPTION");
} catch(Exception ex)
{
System.out.println("GLOBAL EXCEPTION");
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}//main
}