2012-04-13 3 views
1

Bonne journée!Java DB: Aucun pilote approprié trouvé

Je sais qu'il y a eu beaucoup de messages pour ce genre de question, mais j'ai regardé certains d'entre eux et je n'ai pas trouvé la réponse à mon problème puisque j'utilise un Derby intégré.

Je reçois cette erreur:

##THIS IS GENERATED BY THE METHOD printSQLException shown at the code below 
----- SQLException ----- 
SQL State: 08001 
Error Code: 0 
Message: No suitable driver found for jdbc:derby://localhost:1527/recordbookDB 

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException 
    at recordbook.RecordBook.checkHasAccount(RecordBook.java:71) 
    at recordbook.Login.<init>(Login.java:31) 
    at recordbook.Login$1.run(Login.java:168) 
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:647) 
    at java.awt.EventQueue.access$000(EventQueue.java:96) 
    at java.awt.EventQueue$1.run(EventQueue.java:608) 
    at java.awt.EventQueue$1.run(EventQueue.java:606) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:617) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177) 
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:138) 
BUILD STOPPED (total time: 6 minutes 16 seconds) 

Le problème est dans la connexion à la partie de base de données. Ceci est la partie du code (et les méthodes) nécessaires pour voir le problème.

public class RecordBook 
{ 
    private String framework = "embedded"; 
    private String driver = "org.apache.derby.jdbc.EmbeddedDriver"; 
    private String protocol = "jdbc:derby:"; 
    private Connection conn; 

    //this is where everything happens 
    public RecordBook() 
    { 
     //Loading the Driver 
     loadDriver(); 

     //Connecting to the database 
     conn = null; 
     try 
     { 
      Properties props = new Properties(); 
      props.put("user","root"); 
      props.put("password","root"); 
      String dbName = "//localhost:1527/recordbookDB"; 
      conn = DriverManager.getConnection(protocol + dbName, props); //error is here 

     } 
     catch (SQLException sqle) 
     { 
      printSQLException(sqle); 
     } 
    } 

    //BELOW ARE THE METHODS USED ABOVE  
    /** 
    * CODE FROM http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html 
    */ 
    private void loadDriver() 
    { 
     try 
     { 
      Class.forName(driver).newInstance(); 
      System.out.println("Loaded the appropriate driver"); 
     } 
     catch (ClassNotFoundException cnfe) 
     { 
      System.err.println("\nUnable to load the JDBC driver " + driver); 
      System.err.println("Please check your CLASSPATH."); 
      cnfe.printStackTrace(System.err); 
     } 
     catch (InstantiationException ie) 
     { 
      System.err.println("\nUnable to instantiate the JDBC driver " + driver); 
      ie.printStackTrace(System.err); 
     } 
     catch (IllegalAccessException iae) 
     { 
      System.err.println("\nNot allowed to access the JDBC driver " + driver); 
      iae.printStackTrace(System.err); 
     } 
    } 

    /** 
    * CODE FROM http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html 
    * 
    * @param e the SQLException from which to print details. 
    */ 
    public static void printSQLException(SQLException e) 
    { 
     // Unwraps the entire exception chain to unveil the real cause of the exception. 
     while (e != null) 
     { 
      System.err.println("\n----- SQLException -----"); 
      System.err.println(" SQL State: " + e.getSQLState()); 
      System.err.println(" Error Code: " + e.getErrorCode()); 
      System.err.println(" Message: " + e.getMessage()); 
      // for stack traces, refer to derby.log or uncomment this: 
      //e.printStackTrace(System.err); 
      e = e.getNextException(); 
     } 
    } 
+0

Veuillez modifier votre message pour inclure la trace de pile COMPLETE et indiquer quelle instruction dans votre code a lancé l'exception réelle. Incluez également la source de cette déclaration. –

+0

@JimGarrison Okay. Je viens de l'éditer. Merci –

+0

Où est la source de 'recordbook.RecordBook.checkHasAccount()'? –

Répondre

3

Aucun pilote approprié » signifie généralement que l'URL JDBC que vous avez fourni pour vous connecter a une syntaxe incorrecte

plus de détails check out the documentation

vérifiez également que vous avez derby.jar dans votre classpath. Je suggère de placer derby.jar à l'emplacement physique /WEB-INF/lib répertoire de votre éclipse project.Then prendra en charge le reste.

+1

Merci. J'ai trouvé l'URL correcte. Le problème est maintenant sur le CLASSPATH. Il dit: 'Impossible de charger le pilote JDBC org.apache.jdbc.EmbeddedDriver Veuillez vérifier votre CLASSPATH.' –

+0

Checkout the edit answer –

+0

Merci Hardik! J'ai enfin la base de données en état de marche. :) –

Questions connexes