Trouver la db avec Netbeans

cs_Neotaxi Messages postés 21 Date d'inscription dimanche 15 février 2009 Statut Membre Dernière intervention 4 mars 2012 - 4 mars 2012 à 17:28
cs_Neotaxi Messages postés 21 Date d'inscription dimanche 15 février 2009 Statut Membre Dernière intervention 4 mars 2012 - 4 mars 2012 à 22:39
Bonjour,
Je suis tout as fait noob en se qui concerne JDBC.
Voilà je tente de connecter ma database en utilisant ceci dans ma classe main:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package machinecafe;
import java.sql.*;
/**
 *
 * @author Gautier
 */
public class Machinecafe {

    /**
     * @param args the command line arguments
     */
        public static void main(String[] args) {
        // TODO code application logic here
        try{ 
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        }catch(ClassNotFoundException e){
            System.out.println(e);
        }
        System.out.println("eee");
        try{
        Connection con = DriverManager.getConnection("jdbc:derby:Machine", "Machine", "Machine");
        Statement stmt = con.createStatement();
        
        ResultSet rs = stmt.executeQuery("SELECT * FROM DEMO.Table1");
        
        while (rs.next()) {
        String s = rs.getString("Name");
        float n = rs.getFloat("Age");
        System.out.println(s + "   " + n);
    }
        }catch(SQLException e){
            System.err.println(e);
        }                 
     
      }
}

voilà la sortie:
eee
java.sql.SQLException: Impossible de trouver la base de données 'Machine'.

J'ai a peu près tout essayé depuis ce matin mais impossible de faire mieux que ca.

Si je regarde dans les propriété de jdbc:derby://localhost:1527/Machine [Machine on MACHINE]
Je vois que la db est liée au driver:
Driver: org.apache.derby.jdbc.ClientDriver
Mais impossible de mettre Class.forName("org.apache.derby.jdbc.ClientDriver");
Et impossible de mettre le chemin complet de la db (jdbc:derby://localhost:1527/Machine) en argument de l'objet Conection.

Je crois devoir lier le driver EmbeddedDriver à la DB (menu contextuel sur EmbeddedDriver puis connect using) mais là encore cela me donne toujours une erreur:
cannot establish a connection to jdbc:derby://localhost:1527/Machine using org.apache.derby.jdbc.EmbeddedDriver (Unable to find a suitable driver)

J'ai a peu près tout essayé sans même savoir vraiment ce que je faisais, donc je m'en remet à vous!
Si il vous faut plus de précision n'hésitez pas! :D

1 réponse

cs_Neotaxi Messages postés 21 Date d'inscription dimanche 15 février 2009 Statut Membre Dernière intervention 4 mars 2012
4 mars 2012 à 22:39
Quelques changements:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package machinecafe;
import java.sql.*;
/**
 *
 * @author Gautier
 */
public class Machinecafe {

    /**
     * @param args the command line arguments
     */
        public static void main(String[] args) {
        // TODO code application logic here
        try{ 
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        }catch(ClassNotFoundException e){
            System.out.println(e);
        }
        System.out.println("eee");
        try{
        Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/Machine", "Machine", "Machine");
        Statement stmt = con.createStatement();
        
        ResultSet rs = stmt.executeQuery("SELECT * FROM DEMO.Table1");
        
        while (rs.next()) {
        String s = rs.getString("Name");
        float n = rs.getFloat("Age");
        System.out.println(s + "   " + n);
    }
        }catch(SQLException e){
            System.err.println(e);
        }                 
     
      }
}

java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/Machine

C'est ptet mieux! ^^
Faut ptet installer la librairie java DB mais je la trouve pas...
0
Rejoignez-nous