1. Dashboard
  2. Forum
    1. Unerledigte Themen
  3. Mitglieder
    1. Letzte Aktivitäten
    2. Benutzer online
    3. Team-Mitglieder
    4. Trophäen
    5. Mitgliedersuche
  4. Tutorial Bereich
  • Anmelden
  • Registrieren
  • Suche
Dieses Thema
  • Alles
  • Dieses Thema
  • Dieses Forum
  • Seiten
  • Forum
  • Lexikon
  • Erweiterte Suche
  1. Informatik Forum
  2. Webmaster & Internet
  3. Entwicklung

JDBC/MySql - java.sql.SQLException: No suitable driver

  • nphs
  • 17. Dezember 2006 um 15:30
  • Unerledigt
  • nphs
    2
    nphs
    Mitglied
    Punkte
    20
    Beiträge
    3
    • 17. Dezember 2006 um 15:30
    • #1

    Hi ...
    nun, ich bin komplett am verzweifeln. ich probiere mittlerweile seit wochen ein Java Programm zu schreiben, welches auf einer mysql datenbank zugreifen kann. ich habe 3 bis 4 quelltexte die eigentlich richtig sein müssen, trotzdem funktioniert es einfach nicht.

    zu erst hab ich mir das hier runtergeladen -> http://dev.mysql.com/downloads/connector/j/5.0.html

    meine erste frage is: hab ich das richtig installiert ?
    ich habe die datei entpackt und die .jar datei in den C:\Programme\Java\jdk1.5.0_09\lib verschoben. dann habe ich unter systemsteuerung -> system -> erweitert -> umgebungsvariabeln -> systemvariabeln eine neue variabel namens CLASSPATH erstellt und dessen wert auf: C:\Programme\Java\jdk1.5.0_09\lib\mysql-connector-java-5.0.4-bin.jar gesetzt.

    nun hab ich mir erstmal nen vorgefertigen code gesucht umzusehn obs klappt.

    Java
    import java.sql.*;
    
    
    public class Jdbc01 {
      public static void main(String args[]) {
        try {
          Statement stmt;
          ResultSet rs;
    
    
          //Register the JDBC driver
          Class.forName("com.mysql.jdbc.Driver");
    
    
          //Define URL of database server for database named
          // JunkDB by selecting one of the following
          // statements.  I believe that port 1114 is the
          // standard database server port, but I'm not
          // certain.  This value along with the user name and
          // some other information is specified in a file
          // named msql.conf in the Hughes directory which is
          // the installation directory for the mSQL database.
          String url = "jdbc:msql://localhost/laender";
          //String url = "jdbc:msql://localhost:1114/JunkDB";
    
    
    
    
          //Get a connection to the database
          Connection con = DriverManager.getConnection(url,
                                                "root", "mietz");
          //Display URL and connection information
          System.out.println("URL: " + url);
          System.out.println("Connection: " + con);
    
    
          //Get a Statement object
          stmt = con.createStatement();
    
    
          //As a precaution, delete myTable if it already
          // exists as residue from a previous run.  Otherwise,
          // if the table already exists and an attempt is made
          // to create it, an exception will be thrown.
          try{
            stmt.executeUpdate("DROP TABLE myTable");
          }catch(Exception e){
            System.out.print(e);
            System.out.println("No existing table to delete");
          }//end catch
    
    
          //Create a table in the database named myTable.
          stmt.executeUpdate("CREATE TABLE myTable ("
                  + "test_id int,test_val char(15) not null)");
    
    
          //Insert some values into the table
          stmt.executeUpdate("INSERT INTO myTable ("
                       + "test_id, test_val) VALUES(1,'One')");
          stmt.executeUpdate("INSERT INTO myTable ("
                       + "test_id, test_val) VALUES(2,'Two')");
          stmt.executeUpdate("INSERT INTO myTable ("
                     + "test_id, test_val) VALUES(3,'Three')");
          stmt.executeUpdate("INSERT INTO myTable ("
                      + "test_id, test_val) VALUES(4,'Four')");
          stmt.executeUpdate("INSERT INTO myTable ("
                      + "test_id, test_val) VALUES(5,'Five')");
    
    
          //Get another statement object.  This version is
          // compatible with either JDK 1.1 or JDK 1.2, but
          // does not support the rs.absolute(2) statement used
          // later in the JDK 1.2 version.
          stmt = con.createStatement();
    
    
    
    
    /*
          //Get another statement object initialized as shown.
          // This version is compatible with JDK 1.2 but is not
          // compatible with JDK 1.1.  This version is required
          // to support the rs.absolute(2) statement later.
          stmt = con.createStatement(ResultSet.
                                   TYPE_SCROLL_INSENSITIVE,
                                   ResultSet.CONCUR_READ_ONLY);
    */
          //Query the database, storing the result in an object
          // of type ResultSet
          rs = stmt.executeQuery(
                   "SELECT * from myTable ORDER BY test_id");
    
    
          //Use the methods of class ResultSet in a loop
          // to display all of the data in the database.
          System.out.println("Display all results:");
          while(rs.next()) {
            int theInt= rs.getInt("test_id");
            String str = rs.getString("test_val");
            System.out.println("\ttest_id= " + theInt
                                           + "\tstr = " + str);
          }//end while loop
    
    
    /*
          //This block of code only works under JDK 1.2.
          // The absolute() method is not supported by JDK 1.1.
          System.out.println("Display row number 2:");
          if( rs.absolute(2) ) {
            int theInt= rs.getInt("test_id");
            String str = rs.getString("test_val");
            System.out.println("\ttest_id= " + theInt
                                           + "\tstr = " + str);
          }//end if
          //End block supported only by JDK 1.2.
    */
          //Delete the table and close the connection to the
          // database
          stmt.executeUpdate("DROP TABLE myTable");
          con.close();
        }catch( Exception e ) {
          e.printStackTrace();
        }//end catch
      }//end main
    }//end class Jdbc01
    Alles anzeigen

    ich denke mal das nur der anfang hiervon wichtig ist. wenn ich dieses programm starte kriege ich folgende fehlermeldung:

    Code
    init:
    deps-jar:
    compile-single:
    run-single:
    java.sql.SQLException: No suitable driver
            at java.sql.DriverManager.getConnection(DriverManager.java:545)
            at java.sql.DriverManager.getConnection(DriverManager.java:171)
            at Jdbc01.main(Jdbc01.java:25)
    BUILD SUCCESSFUL (total time: 0 seconds)

    irgendwo hab ich das hier gelesen:

    Zitat

    Der Fehler liegt darin dass in der my.cnf von xampp latin1_swedish_ci angegeben ist.
    Ein ersetzen durch z.B. utf8 und utf8_bin behebt das Problem ohne einen alten Driver zu nehmen.

    Regards,
    dj+ji

    das hab ich auch gemacht, jedoch aendert das bei mir nix :frowning_face:

    ich hoffe ihr koennt mir helfen, denn ich sollte das bis heute abend fertig haben.

    danke :)

  • KeinWunder
    7
    KeinWunder
    Mitglied
    Punkte
    490
    Beiträge
    90
    • 17. Dezember 2006 um 16:00
    • #2

    es kann sein das deine IDE einen eigenen Classpath verwendet und die Umgebungsvariable ignoriert
    such mal in deiner IDE nach Classpath, Buildpath oder irgendwas wo du jars zum projekt hinzufügen kannst

    Four stages of acceptance:
    1.) this is worthless nonsense
    2.) this is interesting, but perverse, point of view
    3.) this is true, but quite unimportant
    4.) I alwas said so
    J.B.S. Haldane

  • Paulchen
    1
    Paulchen
    Gast
    • 17. Dezember 2006 um 16:03
    • #3

    Bist du sicher, dass die URL für die Verbindung zur Datenbank nicht

    Code
    String url = "jdbc:m[COLOR='Red']y[/COLOR]sql://localhost/laender";


    heißen sollte?

    EDIT: Der CLASSPATH sollte passen; wäre der MySQL-Konnektor nicht im CLASSPATH, würde Class.forName(...) eine ClassNotFoundException werfen.

  • nphs
    2
    nphs
    Mitglied
    Punkte
    20
    Beiträge
    3
    • 17. Dezember 2006 um 16:31
    • #4

    jo dankeschoen .. das war dumm von mir ..

    naja, nun krieg ich nen neuen fehler:

    Code
    init:
    deps-jar:
    Compiling 1 source file to C:\Dokumente und Einstellungen\advanced\JavaApplication5\build\classes
    compile-single:
    run-single:
    java.sql.SQLException: Unknown initial character set index '48' received from server. Initial client character set can be forced via the 'characterEncoding' property.
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
            at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2345)
            at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3913)
            at com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)
            at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
            at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
            at java.sql.DriverManager.getConnection(DriverManager.java:525)
            at java.sql.DriverManager.getConnection(DriverManager.java:171)
            at Jdbc01.main(Jdbc01.java:25)
    BUILD SUCCESSFUL (total time: 2 seconds)
    Alles anzeigen

    ich hab auch noch nen anderen quellcode:

    Java
    import java.sql.*;
    
    
    public class sql {
    
        public static void main (String[] args) {
        // JDBC
        Connection           connection = null;
        Statement            statement = null;
    
        // connecten
        System.out.println("connecting...");
    
        try {
    
            // Verbindung zu MySql
    
            // Treiber festlegen
            Class.forName("com.mysql.jdbc.Driver");
    
            // Verbindung aufbauen
            // DB-Name, Kennung, Password
            connection = DriverManager.getConnection
                    ("jdbc:mysql://localhost/laender","root","mietz");
            // Statement für Sql-Befehle erzeugen
            statement = connection.createStatement();
        }
    
        catch (ClassNotFoundException err) {
            System.err.println("/nDB-Driver nicht gefunden");
            System.err.println(err);
        }
    
        catch (SQLException err) {
            System.err.println("\nConnect nicht moeglich");
            System.err.println(err);
        }
    
        }
    
    }
    Alles anzeigen

    und der gibt mir folgende fehlermeldung.

    Code
    init:
    deps-jar:
    Compiling 1 source file to C:\Dokumente und Einstellungen\db\mySql\build\classes
    compile-single:
    run-single:
    connecting...
    
    
    Connect nicht moeglich
    java.sql.SQLException: Unknown initial character set index '48' received from server. Initial client character set can be forced via the 'characterEncoding' property.
    BUILD SUCCESSFUL (total time: 0 seconds)
    Alles anzeigen
  • nphs
    2
    nphs
    Mitglied
    Punkte
    20
    Beiträge
    3
    • 17. Dezember 2006 um 16:35
    • #5

    omg es GEHT !!!!!!!!!!!!!!!!!!
    ich habe xampp nochmal neuinstalliert und diesen einen trick da verwendet von wegen utf8 blubb ! und nun geht es ! gelobt sei der herr ;D

    danke danke danke danke danke danke danke danke

  • Maximilian Rupp 27. Dezember 2024 um 12:05

    Hat das Thema aus dem Forum Programmieren nach Entwicklung verschoben.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!

Benutzerkonto erstellen Anmelden

Rechtliches

Impressum

Datenschutzerklärung