Reputation: 1791
Sorry if the answer to this problem is fairly obvious. I just don't understand what the following errors mean when I use a try/catch to connect to my database (all I know is that the catch part is what executes because of the print statement - "Error: Couldn't make a database connection. See method 'dbConnect'."
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Error: Couldn't make a database connection. See method 'dbConnect'.
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at runone.DBconnector.openConnection(DBconnector.java:26)
at runone.loginScreen.dbConnect(loginScreen.java:1592)
at runone.loginScreen.viewScreenState(loginScreen.java:1371)
at runone.loginScreen.jButton1ActionPerformed(loginScreen.java:1230)
at runone.loginScreen.access$19(loginScreen.java:1219)
at runone.loginScreen$20.actionPerformed(loginScreen.java:1177)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6373)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6138)
at java.awt.Container.processEvent(Container.java:2085)
at java.awt.Component.dispatchEventImpl(Component.java:4735)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Component.dispatchEvent(Component.java:4565)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4621)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
at java.awt.Container.dispatchEventImpl(Container.java:2129)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4565)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:679)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:638)
at java.awt.EventQueue$1.run(EventQueue.java:636)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:652)
at java.awt.EventQueue$2.run(EventQueue.java:650)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:649)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
EDIT: Here is the code that makes the connection:
public void dbConnect() {
DBconnector db = new DBconnector();
try {
db.openConnection();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error: Couldn't make a database connection. See method 'dbConnect'.");
}
}
Upvotes: 0
Views: 839
Reputation: 1501626
The first line of the stack trace is the most important one here:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
That suggests you haven't got the MySQL driver on your classpath.
The rest of the exception is just the stack trace for the operation leading up to the ClassNotFoundException
- so your dbConnect
method has called openConnection
which has called Class.forName
etc.
Upvotes: 2