Bonjour,
Voici mon problème : je veux utiliser une BdD derby en mode embarqué.
Mon appli fonctionne correctement sur Netbeans et c'est au moment ou je souhaite l'utiliser sans Netbeans qu'il n’accède plus à ma BdD.
J'ai regardé tous les posts concernant ce problème et je ne vois pas de solution.
Le driver est bien utilisé comme le montre la log, mais c'est lors du lancement de ma première requête que la BdD ne répond plus.
Voici le message d'erreur :
*** Driver loaded.
Exception in thread "main" java.lang.NoClassDefFoundError: Bean/Type_inconnu
at dao.DAOType_inconnu.existeTypeByType(DAOType_inconnu.java:134)
at gestionlistefilm.EnregistrementFilms.verif_type(EnregistrementFilms.java:137)
at gestionlistefilm.EnregistrementFilms.debut(EnregistrementFilms.java:67)
at gestionlistefilm.GestionListeFilm.main(GestionListeFilm.java:41)
Caused by: java.lang.ClassNotFoundException: Bean.Type_inconnu
at java.net.URLClassLoader$1.run(Unknown Source)
voici la classe de connexion :
Le message d'erreur n'indique pas que la BdD n'est pas accessible c'est qu'il la trouve bien.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 package jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; //--------------------------------------------------------- public class JdbcUtil { private static final String DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver"; private static final String URL = "jdbc:derby:C:/Users/pbonnet/Documents/NetBeansProjects/GestionListeFilm/ListeFichiers;create=true"; private static final String USER = "APP"; private static final String PASSWORD = ""; static { // Chargement du pilote // Ne doit avoir lieu qu'une seule fois try { Class.forName(DRIVER_NAME).newInstance(); System.out.println("*** Driver loaded."); } catch (ClassNotFoundException e) { System.err.println("*** ERROR: Driver " + DRIVER_NAME + " not found"); } catch (InstantiationException e) { System.err.println("*** ERROR: Impossible to create an instance of " + DRIVER_NAME); System.err.println(e.getMessage()); } catch (IllegalAccessException e) { System.err.println("*** ERROR: Impossible to create an instance of " + DRIVER_NAME); System.err.println(e.getMessage()); } } public static Connection getConnection() throws SQLException { return DriverManager.getConnection(URL, USER, PASSWORD); } public static void close(final Connection cx) { if (cx != null) { try { cx.close(); } catch (SQLException e) { System.err.println("Impossible to close connection"); System.err.println(e.getMessage()); } } } public static void close(final Statement st) { if (st != null) { try { st.close(); } catch (SQLException e) { System.err.println("Impossible to close statement"); System.err.println(e.getMessage()); } } } public static void close(final ResultSet rs) { if (rs != null) { try { rs.close(); } catch (SQLException e) { System.err.println("Impossible to close resultSet"); System.err.println(e.getMessage()); } } } public static String getURL() { return URL; } }
Sinon il mettrait un autre message.
Voici ma classe d'interrogation à la BdD :
Le bean existe, l'appli fonctionne sous NetBeans.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 package dao; import Bean.Type_inconnu; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import jdbc.DAOException; import jdbc.JdbcUtil; public class DAOType_inconnu { public Type_inconnu getTypeByType(final String Type) throws DAOException { Connection cx = null; PreparedStatement pst = null; ResultSet rs = null; Type_inconnu type = null; // Tester la connexion avec la BdD try { Connection connection = JdbcUtil.getConnection(); // utilisation de la connexion connection.close(); } catch (SQLException e) { throw new DAOException( "La base de données n'est pas accessible(" + JdbcUtil.getURL() + ")", e); } try { cx = JdbcUtil.getConnection(); //pst = cx.prepareStatement("SELECT * FROM attaquecatapulte where idemplacement = ?"); pst = cx.prepareStatement("SELECT * FROM TYPE_inconnu WHERE TYPE = ?"); pst.setString(1, Type); rs = pst.executeQuery(); while (rs.next()) { type = new Type_inconnu( rs.getInt("INDEX"), rs.getString("TYPE"), rs.getString("CATEGORIE"), rs.getString("NOM")); return type; } } catch (SQLException e) { throw new DAOException( "Impossible to process getTypeByType(TYPE : " + type + ")", e); } finally { JdbcUtil.close(rs); JdbcUtil.close(pst); JdbcUtil.close(cx); } return null; } public boolean existeTypeByType(final String Type) throws DAOException { Connection cx = null; PreparedStatement pst = null; ResultSet rs = null; Type_inconnu type = null; // Tester la connexion avec la BdD try { Connection connection = JdbcUtil.getConnection(); // utilisation de la connexion connection.close(); } catch (SQLException e) { throw new DAOException( "La base de données n'est pas accessible(" + JdbcUtil.getURL() + ")", e); } try { cx = JdbcUtil.getConnection(); pst = cx.prepareStatement("SELECT * FROM TYPE_inconnu WHERE TYPE = ?"); pst.setString(1, Type); rs = pst.executeQuery(); while (rs.next()) { type = new Type_inconnu( rs.getInt("INDEX"), rs.getString("TYPE"), rs.getString("CATEGORIE"), rs.getString("NOM")); return true; } } catch (SQLException e) { throw new DAOException( "Impossible to process existeTypeByType(TYPE : " + Type + ")", e); } finally { JdbcUtil.close(rs); JdbcUtil.close(pst); JdbcUtil.close(cx); } return false; } }
Faut-il installer autre chose que le JDK et les derby.jar ?
Partager