Bonjour, voilà j'ai commencé avec netbeans et j'arrive pas à resoudre le probleme la deçu :
en fait j'ai 3 fichier DBConnexion.java, ContactsModel.java et OceaneFinal.java et une error de :
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 init: deps-jar: Compiling 1 source file to /home/lova/netbeans/oceaneFinal/build/classes compile: run: OK connexion réussie... insert into prestataire(nomPRSTT, localPRSTT, typePRSTT, categoriePRSTT, capacitePRSTT, adrPRSTT, cpPRSTT, nifPRSTT, statPRSTT, mail1PRSTT, mail2PRSTT, tel1PRSTT, tel2PRSTT, tel3PRSTT, rcPRSTT) values ('fcvfv', 'Item 1', 'HOTEL', 'HAUT DE GAMME', '', '', '', '', '', '', '', '', '', '', ''); java.lang.NullPointerException at examples.ContactsModel.updatePRSTT(ContactsModel.java:74) at examples.OceaneFinal.jBOKPRSTTActionPerformed(OceaneFinal.java:533) at examples.OceaneFinal.access$000(OceaneFinal.java:15) at examples.OceaneFinal$1.actionPerformed(OceaneFinal.java:416) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) at java.awt.Component.processMouseEvent(Component.java:5488) at javax.swing.JComponent.processMouseEvent(JComponent.java:3126) at java.awt.Component.processEvent(Component.java:5253) at java.awt.Container.processEvent(Container.java:1966) at java.awt.Component.dispatchEventImpl(Component.java:3955) at java.awt.Container.dispatchEventImpl(Container.java:2024) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822) at java.awt.Container.dispatchEventImpl(Container.java:2010) at java.awt.Window.dispatchEventImpl(Window.java:1778) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.EventQueue.dispatchEvent(EventQueue.java:463) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
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 DBConnexion.java : /* * DBConnexion.java * * Created on 15 janvier 2007, 11:14 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package examples; import java.sql.*; /** * * @author lova */ public class DBConnexion { private Connection con; private Statement stmt; /** Creates a new instance of DBConnexion */ public DBConnexion() { String username = "root"; String password = "xxxxx"; String url = "jdbc:mysql://192.168.0.42:3306/DBOceane"; try{ Class.forName("org.gjt.mm.mysql.Driver"); //Class.forName("com.mysql.jdbc.Driver"); }catch(java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try{ con = DriverManager.getConnection(url, username, password); stmt = con.createStatement(); System.out.println("OK connexion réussie..."); } catch(SQLException ex){ System.out.println(ex.getMessage()); } } public Statement getStmt() { return stmt; } public Connection getCon() { return con; } public ResultSet executeQuerry( String aQuerry, String aCritere) throws Exception { if(aCritere.equals("")) return stmt.executeQuery(aQuerry) ; else return stmt.executeQuery(aQuerry + " WHERE " + aCritere) ; } public ResultSet Querry( String aQuerry, String aCritere) throws Exception { if(aCritere.equals("")) return stmt.executeQuery(aQuerry) ; else return stmt.executeQuery(aQuerry + aCritere) ; } public int QuerryUpdate( String aQuerry, String aCritere) throws Exception { if(aCritere.equals("")) return stmt.executeUpdate(aQuerry) ; else return stmt.executeUpdate(aQuerry + " WHERE " + aCritere) ; } public void closeConnexion() throws Exception { con.close() ; } }
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 COntactsModel.java : package examples; import java.sql.*; import java.util.*; import javax.swing.*; import javax.swing.event.*; /** * Model of Contacts application. * * @author Jan Stola */ public class ContactsModel { // Constants for database objects private static final String PRSTT_TABLE = "prestataire"; private static final String PRSTT_NOM = "nomPRSTT"; private static final String PRSTT_LOCAL = "localPRSTT"; private static final String PRSTT_TYPE = "typePRSTT"; private static final String PRSTT_CATEGORIE = "categoriePRSTT"; private static final String PRSTT_CAPACITE = "capacitePRSTT"; private static final String PRSTT_ADRESSE = "adrPRSTT"; private static final String PRSTT_CP = "cpPRSTT"; private static final String PRSTT_NIF = "nifPRSTT"; private static final String PRSTT_STAT = "statPRSTT"; private static final String PRSTT_RC = "rcPRSTT"; private static final String PRSTT_MAIL1 = "mail1PRSTT"; private static final String PRSTT_MAIL2 = "mail2PRSTT"; private static final String PRSTT_TEL1 = "tel1PRSTT"; private static final String PRSTT_TEL2 = "tel2PRSTT"; private static final String PRSTT_TEL3 = "tel3PRSTT"; ResultSet rs = null; public DBConnexion connect; public String sql; public Statement stmt; public Connection con; public void connexion() { try{ connect = new DBConnexion(); stmt = connect.getStmt(); con = connect.getCon(); } catch(Exception ex){ System.out.println(ex.getMessage()); } } /** * Updates the selected contact or inserts a new one (if we are * in the insert mode). * * @param firstName first name of the contact. * @param lastName last name of the contact. * @param title title of the contact. * @param nickname nickname of the contact. * @param displayFormat display format for the contact. * @param mailFormat mail format for the contact. * @param emails email addresses of the contact. */ public void updatePRSTT(String nomPRSTT, String localPRSTT,String typePRSTT,String categoriePRSTT, String capacitePRSTT, String adressePRSTT, String cpPRSTT, String nifPRSTT, String statPRSTT, String rcPRSTT, String mail1PRSTT,String mail2PRSTT,String telPRSTT,String tel1PRSTT,String tel2PRSTT) throws Exception { try { sql = "insert into " + PRSTT_TABLE + "(" + PRSTT_NOM + ", "+ PRSTT_LOCAL + ", " + PRSTT_TYPE + ", " + PRSTT_CATEGORIE + ", "+ PRSTT_CAPACITE + ", " +PRSTT_ADRESSE + ", " + PRSTT_CP + ", " +PRSTT_NIF+ ", " +PRSTT_STAT+ ", " +PRSTT_MAIL1+ ", " +PRSTT_MAIL2+ ", " +PRSTT_TEL1+ ", " +PRSTT_TEL2+ ", " +PRSTT_TEL3+", " +PRSTT_RC+ ") values ("+ encodeSQL(nomPRSTT) + ", " + encodeSQL(localPRSTT) + ", " + encodeSQL(typePRSTT) + ", "+ encodeSQL(categoriePRSTT) + ", " + encodeSQL(capacitePRSTT) + ", " + encodeSQL(adressePRSTT) + ", " + encodeSQL(cpPRSTT) + ", " + encodeSQL(nifPRSTT) + ", " + encodeSQL(statPRSTT) + ", " + encodeSQL(mail1PRSTT) + ", " + encodeSQL(mail2PRSTT) + ", " + encodeSQL(telPRSTT) + ", " + encodeSQL(tel1PRSTT) + ", " + encodeSQL(tel2PRSTT) + ", " + encodeSQL(rcPRSTT) + ");"; System.out.println(sql); connect.QuerryUpdate(sql,""); connect.closeConnexion(); System.out.println("vita le execution"); } catch (SQLException sqlex) { System.out.println("Querry problem "); sqlex.printStackTrace(); } } // Helper method that escapes special SQL characters and encloses the text into quotes private String encodeSQL(String text) { text = text.replaceAll("'", "''"); return "'" + text + "'"; } }
merci de votre repons
Partager