Class not found Exception

Status
Nicht offen für weitere Antworten.

nieselfriem

Bekanntes Mitglied
Hallo!

Ich folgendes kleines Programm geschrieben

Code:
import java.sql.*;
public class sql {
  
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String url ="jdbc:mysql://localhost:3306/mysql";
        String user="root";
        String pass="";
        
        try {
            Class.forName( "com.mysql.jdbc.Driver" );
        } catch( Exception e ) {
            System.out.println( "Probleme JDBC-ODBC." );
            return;
       }
        
        Statement befehl=null;
        Connection verbindung=null;
        try {
            verbindung=DriverManager.getConnection(url,user,pass);
            befehl=verbindung.createStatement();
        } catch (Exception e) {
            System.err.println("Verbindung zu "+url+" konnte nicht hergestellt werden");
        }
        try {
            ResultSet daten;
            befehl.executeQuery("use webshop");
            daten=befehl.executeQuery("SELECT * FROM Bestellungen;");
            System.out.println();
            System.out.println("Kundennummer\t Bestellid\t Bestellpopsid");
            System.out.println();
            int kdnr, bestellid, posid;
            while(daten.next())
            {
                kdnr=daten.getInt("Kundennummer");
                bestellid=daten.getInt("Bestellid");
                posid=daten.getInt("Bestellposid");
                System.out.println(" "+kdnr+ "\t\t "+bestellid+ "\t\t "+posid);
            }
  
        }catch(Exception e) {
            e.printStackTrace();
        }
                
        
        // TODO code application logic here
    }
    
}

Dieses funktioniert auch ganz gut unter Windows mittels Netbeans. Wen ich jedoch unter Debian versuche mit folgendem Befehl
Code:
java -cp mysql-connector-java-3.1.14-bin.jar sql
dieses Programm auszuführen kommt folgende Fehlermeldung:
Code:
java.lang.ClassNotFoundException: sql not found in java.lang.ClassLoader$1{urls=[file:/home/georg/java/mysql-connector-java-3.1.14-bin.jar], parent=null}
   at java.net.URLClassLoader.findClass (URLClassLoader.java:870)
   at java.lang.ClassLoader.loadClass (ClassLoader.java:359)
   at java.lang.ClassLoader$1.loadClass (ClassLoader.java:1333)
   at java.lang.ClassLoader.loadClass (ClassLoader.java:310)
   at java.lang.VirtualMachine.main (VirtualMachine.java:99)

Was läuft da falsch?

Gruß niesel
 

DaKo

Bekanntes Mitglied
probier mal:

java -cp mysql-connector-java-3.1.14-bin.jar sql.class

vorher natürlich compilieren ;)
 
S

SlaterB

Gast
.class schnell wieder vergessen ;)
aber du musst das aktuelle Verzeichnis in den ClassPath aufnehmen:

java -cp .:mysql-connector-java-3.1.14-bin.jar sql


. steht für aktuelles Verzeichnis
unter Windows ; statt : als Trennzeichen
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
algebraiker Eclipse RCP - no persistent classes found for query class Datenbankprogrammierung 4
S MSSQL JDBC "Driver class not found" Datenbankprogrammierung 9
T org.hibernate.MappingException: entity class not found Datenbankprogrammierung 4
D MySQConnextor Class not found obwohl BuildPfad konfiguriert Datenbankprogrammierung 6
torresbig MySQL hibernate - could not resolve entity class ... (Datenbank Anfänger) Datenbankprogrammierung 19
H Java Class zum komprimieren von Jpeg-Images zum Einbinden in Oracle DB - Bild als blob (in und out) Datenbankprogrammierung 23
D MySQL Transaktionen in Entity-Class Datenbankprogrammierung 15
S Table per Class Datenbankprogrammierung 2
temi Wie kann ich "Class" in einer DB speichern? Datenbankprogrammierung 2
T Hibernate und inner class Datenbankprogrammierung 0
P GWT Applikation-The method forName(String) is undefined for the type Class Datenbankprogrammierung 10
I MySQL MATLAB: Class.forName wirft ClassNotFoundException Datenbankprogrammierung 4
S Firebird NoClassDefFoundError trotz erfolgreichem Class.forName(...) unter Linux Datenbankprogrammierung 5
H Fat Jar Export: Could not find class-path entry for 'C:Java/jdk/mysql-connector-java- Datenbankprogrammierung 3
M ClassNotFoundException bei Class.forName(xx) Datenbankprogrammierung 6
B java.lang.Class.forName0(Native Method) Datenbankprogrammierung 3
B SQLite + jdbc + IntelliJ-Consumer = "No suitable driver found..." Datenbankprogrammierung 15
Maxim6394 JPA: IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST Datenbankprogrammierung 1
Kirby.exe SQL-Exception: Column not found Datenbankprogrammierung 6
D MySQL No Suitable Drivers found Datenbankprogrammierung 4
J RESTServie + JDBC + No suitable driver found for jdbc Datenbankprogrammierung 4
D HSQLDB user lacks privilege or object not found Datenbankprogrammierung 6
M User lacks privilege or object not found Datenbankprogrammierung 3
B No suitable driver found for jdbc:oracle:thin:@$HOST:$PORT:$SID Datenbankprogrammierung 7
W No data found: SQL-Abfrage funktioniert nur beim Debuggen Datenbankprogrammierung 3
K JDBC Driver not found Datenbankprogrammierung 10
F GWT und Hibernate - gwt.dev.Compler not found Datenbankprogrammierung 3
AMStyles No suitable driver found for Datenbankprogrammierung 4
A No suitable driver found for jdbc:microsoft:sqlserver... Datenbankprogrammierung 9
N Derby/JavaDB No suitable driver found Datenbankprogrammierung 14
I java.sql.SQLException: No data found Datenbankprogrammierung 3
StYxXx Microsoft-SQL: No suitable driver found Datenbankprogrammierung 11
N Hsqldb und text tables source not found Datenbankprogrammierung 5
G Das tolle "No suitable driver found" Datenbankprogrammierung 4
B Source not found // Java MySQL (eclipse) Datenbankprogrammierung 4
P Fehlermeldung "source not found" Datenbankprogrammierung 2
M java.sql.SQLException: No data found Datenbankprogrammierung 9
KOKASS Exception bei Datenbankconnect Datenbankprogrammierung 9
S MySQL hibernate exception: illegal state exception : entityManagerFactory is closed Datenbankprogrammierung 5
G MySQL Java Problem: Nullpointer Exception obwohl Daten vorhanden sind? Datenbankprogrammierung 2
G PostgreSQL Nach Monaten auf einmal ClassNotFound-Exception Datenbankprogrammierung 3
K JPA Projekt Exception Datenbankprogrammierung 7
C jpa, exception Predeployment of PersistenceUnit failed Datenbankprogrammierung 1
M CommunicationLinkError - NullPointer Exception Datenbankprogrammierung 11
T MongoDB: Morphia REST 505 Exception Tomcat Datenbankprogrammierung 2
M SQL-Exception trotz funktionierendem SELECT Datenbankprogrammierung 4
N JDBC: rollback() bei Exception geht nicht!? Datenbankprogrammierung 1
M SQL Exception Datenbankprogrammierung 6
L Probleme mit DriverManager.getConnection(..) - Endlosschleife, Java Absturz, Keine Exception Datenbankprogrammierung 4
D Hibernate SaveOrUpdate Exception Datenbankprogrammierung 2
E MySQL Hibernate mit JaxWS führt zu LazyInitialization Exception Datenbankprogrammierung 8
E PostgreSQL Exception too ...many clients already bei DB-Abfrage Datenbankprogrammierung 14
T java sql exception getDate() Datenbankprogrammierung 2
O Viele Verbindungen-Exception bei insert Daten zur MySQL-Datenbank Datenbankprogrammierung 2
E Sql Exception Datenbankprogrammierung 14
M NestedTransaction- Exception in Hibernate Datenbankprogrammierung 15
F Derby/JavaDB SQL-Exception...Aber wieso!? :/ Datenbankprogrammierung 2
T Exception ResultSet Datenbankprogrammierung 7
Paristick MSSQL - JDBC Exception beim Registrieren Datenbankprogrammierung 5
S Null Pointer exception statement Datenbankprogrammierung 8
G JDBC Exception Datenbankprogrammierung 3
S ResultSet einer Datenbankabfrage - Nullpointer Exception Datenbankprogrammierung 13
F Derby/JavaDB Exception - Cannot accept Null Value (help) Datenbankprogrammierung 10
G Stored Procedure Exception Handling Datenbankprogrammierung 3
C SQL Exception auf Unique überprüfen Datenbankprogrammierung 5
B Hibernate+JPA Exception in persistence.xml Datenbankprogrammierung 5
L SQL Exception Problem Datenbankprogrammierung 7
M hilfe zur einer Exception Datenbankprogrammierung 2
J Nullpointer Exception bei Zugriff auf Datenbank Datenbankprogrammierung 13
A MySQL Anbindung - Exception Handling Datenbankprogrammierung 2
R SQL Exception: Cursor position not valid Datenbankprogrammierung 7
O Oracle 11g wirft bei 90 % der installation eine Exception ? Datenbankprogrammierung 5
R Warum kommt eine Exception bei instanceof ? Datenbankprogrammierung 4
B SQL Exception Datenbankprogrammierung 9
E Datenbankverbindung Java MySQL Exception Datenbankprogrammierung 10
A Exception in thread "AWT-EventQueue-0" java.lang.N Datenbankprogrammierung 4
M SQL Exception bei LIMIT Datenbankprogrammierung 11
megachucky Problem mit: SQL Exception Before start of result set Datenbankprogrammierung 2
W updateRow() schmeißt eine Exception, weil schreibgeschützt Datenbankprogrammierung 6
M Sql Anfrage wirft Exception Datenbankprogrammierung 5
6 Communications link failure due to underlying exception Datenbankprogrammierung 10
R SQL Exception "Weiterleiten der Egebnissmenge" Datenbankprogrammierung 15
märliprinz Exception in thread "main" java.lang.OutOfMemoryEr Datenbankprogrammierung 9
S Java SQL-Exception bei Zugriff auf MSAccess Datenbankprogrammierung 2
K Exception bei Verbindungsaufbau Oracle Datenbank Datenbankprogrammierung 13
L "desc tablename" liefert SQL Exception mit execute Datenbankprogrammierung 6
M SQL Exception Datenbankprogrammierung 3
M Problem mit dem ActionListener und SQL Exception Datenbankprogrammierung 6
D Exception bei ResultSet.moveToInsertRow Datenbankprogrammierung 6
EagleEye problem mit exception Datenbankprogrammierung 2
L UPDATE löst Exception aus Datenbankprogrammierung 6
V Exception beim Speichern von eingegebenen Daten in Tabelle Datenbankprogrammierung 2
G ich bekomm immer die exception grrrr Datenbankprogrammierung 3
D Unklare SQL Exception Datenbankprogrammierung 3

Ähnliche Java Themen

Neue Themen


Oben