# Warum klappt connect zur MySQL-DB nicht



## Guest (10. Sep 2004)

Hallo Leute,

habe folgenden Code (stark verkürzt):

```
protected String dbTreiber = "com.mysql.jdbc.Driver";
protected String dbName = "java";
protected String dbUrl = "jdbc:mysql:///" + dbName;
protected String user = "root";
protected String passwort = "";

public void connectDB()
{
	try {
		Class.forName("com.mysql.jdbc.Driver").newInstance(); 
		Connection conn = DriverManager.getConnection(dbUrl, user, passwort); 
		System.out.println("Verbunden"); 
	}
	catch(Exception e) {
		e.printStackTrace();
	}
}
```
Warum klappt die Verbindung nicht???

Die Fehlermeldung:
--------------------------------------------------------------------------------------
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
	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)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at S_AnlegenKunde.connectDB(S_AnlegenKunde.java:231)
	at S_AnlegenKunde$1.actionPerformed(S_AnlegenKunde.java:218)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
--------------------------------------------------------------------------------------

Mein CLASSPATH sieht wie folgt aus: C:\Programme\Java\jdk1.5.0\lib\mysql-connector-java-3.1.4-beta-bin.jar
Habe Ihn auch in die AUTOEXEC.BAT eingetragen, so dass der CLASSPATH beim Neustart automatisch gesetzt ist.

Vielen Dank für Eure Hilfe im Voraus.

Gruß
Sven.


----------



## foobar (10. Sep 2004)

Auf das newInstance() kannst du verzichten

```
Class.forName("com.mysql.jdbc.Driver");
```


----------



## DP (10. Sep 2004)

und der findet deinen treiber nicht. mal deine classpath checken


----------



## stev.glasow (10. Sep 2004)

Das Problem wurde im Chat gelöst: der Classpath wurde nicht gesetzt.


----------

