Problem mit MySQL

pdikij

Mitglied
Hallo Leute!

Ich habe folgendes Problem...
Als ich die Anwendung Separat laufen ließ hatte ich keine Probleme bei Datenbankverbindungsaufbau.
Jetzt wollte ich diese Anwendung aus einem anderen Programm aufrufen und damit arbeiten...
Aber es gibt mir immer diese Fehlermeldung aus:

java.lang.ClassNotFoundException: org.gjt.mm.mysql.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 showAll.MySQL_JFrame.initDB(MySQL_JFrame.java:134)
at showAll.MySQL_JFrame.connect_jButton2MousePressed(MySQL_JFrame.java:394)
at showAll.MySQL_JFrame.access$0(MySQL_JFrame.java:385)
at showAll.MySQL_JFrame$2.mousePressed(MySQL_JFrame.java:276)
at java.awt.AWTEventMulticaster.mousePressed(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.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at showAll.MySQL_JFrame.initDB(MySQL_JFrame.java:146)
at showAll.MySQL_JFrame.connect_jButton2MousePressed(MySQL_JFrame.java:394)
at showAll.MySQL_JFrame.access$0(MySQL_JFrame.java:385)
at showAll.MySQL_JFrame$2.mousePressed(MySQL_JFrame.java:276)
at java.awt.AWTEventMulticaster.mousePressed(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.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)


Nun als ich dieses Programm mit Access ausprobiert habe hat es immer einwand frei funktioniert... Und MySql nicht mehr... :suspekt:
Könnte mir jemand vielleicht ein Tipp geben woran es liegen könnte? :confused:

Hier ist mein Quellcode:

Code:
private void showTableContent(){
        if (con != null && dbmd != null){
            try{
                
                Statement stmt = con.createStatement();
                String db = (String)this.dbs_jComboBox1.getSelectedItem();
                if (db == null || db == "")
                    return;
                stmt.execute("USE " + db);
                String tbl = (String)this.tbls_jComboBox1.getSelectedItem();
                if (tbl == null || tbl == "")
                    return;
                ResultSet rs = stmt.executeQuery("SELECT * FROM " + tbl);
                tblDataModel = new DefaultTableModel();
                Vector clmHeader = new Vector();
                Vector dataVector = new Vector();
                
                ResultSetMetaData rsmd = rs.getMetaData();
                int clmCnt = rsmd.getColumnCount();
                for(int i = 1; i <= clmCnt;i++)
                    clmHeader.addElement(rsmd.getColumnName(i));
                
                while(rs.next()){
                    Vector rowVector = new Vector();
                    for(int i = 1; i <= clmCnt; i++){
                        rowVector.addElement(rs.getString(i));
                    }
                    dataVector.addElement(rowVector);
                }
                
                tblDataModel.setDataVector(dataVector,clmHeader);
                
                this.jTable1.setModel(tblDataModel);
                this.jTable1.updateUI();
                
               // System.out.println("finished");

            }catch(SQLException sqle){
                sqle.printStackTrace();
            }
        }
    }
    
    private void initDB(){
        //Treiberklasse Laden
        try{
            Thread.currentThread().getContextClassLoader().loadClass(driverClass).newInstance();
        }catch(ClassNotFoundException cnfe){
            cnfe.printStackTrace();
        }catch(InstantiationException ie){
            ie.printStackTrace();
        }catch(IllegalAccessException iae){
            iae.printStackTrace();
        }
        
        //Verbindung zur Datenbank Aufbauen
        
        try{
            this.con = DriverManager.getConnection(this.dbUrl,this.user,this.password);
            this.connected = true;
            this.status_jTextField1.setText("connected");
            //System.out.println("Connected");
            dbmd = con.getMetaData();
            
            //Verfügbare Datenbanken ermitteln
            listDatabases();
            
            // con.close();
        }catch(SQLException sqle){
            sqle.printStackTrace();
        }
        
        
    }

Schon mal Danke im Vorraus!

pdikij
 
Er findet den Treiber nicht, weil dieser wahrscheinlich nicht im Klassenpfad liegt.
Musst also dafür sorgen das die Klasse

Code:
org.gjt.mm.mysql.Driver
im Klassenpfad sich befindet..

*grüssle*
MeinerEiner
 
Vielen Dank
Ich hab den Fehler beseitigt!
Ich musste nur im Eclipse die Treiber-Bibliothek neu im Java Build Path laden!
Guter Hinweis!

pdikij
 
Zurück