-
Connector/J not working
Program returns this error:
Code:
java.lang.NoClassDefFoundError: com/mysql/jdbc/DocsConnectionPropsHelper
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.DocsConnectionPropsHelper
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Exception in thread "main"
I've added the Connector/J JAR file to the project in Eclipse, but it just doesn't seem to be working. :(
Trying to get it working with this program:
Code:
import java.sql.*;
class Connect
{
public static void main(String args[])
{
Connection conn = null;
try
{
String userName = "user";
String password = "pass";
String url = "jdbc:mysql://host:port/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(e);
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}