IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

NetBeans Java Discussion :

connexion netbeans 5.5 et mysql


Sujet :

NetBeans Java

  1. #1
    Candidat au Club
    Inscrit en
    Janvier 2007
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 2
    Points : 3
    Points
    3
    Par défaut connexion netbeans 5.5 et mysql
    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

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Août 2006
    Messages
    568
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 568
    Points : 167
    Points
    167
    Par défaut
    Bonjour,
    je ne suis pas sûr si j'ai bien compris ton problème, mais une chose est sur c'est que Jboss utlise hypesonic par defaul, glass fish utlise...( autre que mysql!) tu dois :

    1)ajouter le mysql-connector-java-3.1.8-bin.jar (par exemple) dans Jboss_Home\server\default\lib (si t'utilise Jboss par exempe).

    2) chager le contenu des fichiers de conf dans Jboss_Home\server\default\conf pour qu'ils prennet en charge Mysql
    par exemple dans le fichier standardjaws.xml :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     [...]<jaws>
       <datasource>java:/MySqlDS</datasource>
       <type-mapping>mySQL</type-mapping>
    	<!-- <type-mapping>Hypersonic SQL</type-mapping> -->
       <debug>false</debug>
    [...]
    dans le fichier login-config.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <application-policy name = "MySqlDbRealm"> 
           <authentication> 
              <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" 
                 flag = "required"> 
                 <module-option name ="principal">sa</module-option> 
                 <module-option name ="userName">sa</module-option> 
                 <module-option name ="password"></module-option> 
                 <module-option name ="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MySqlDS</module-option> 
              </login-module> 
           </authentication> 
        </application-policy>
    il faut aussi que tu regardes les privilège de ta BD,
    Voilà j'espère que ceci te sera util

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème de connexion NetBeans avec MySQL
    Par Patrick Dubois dans le forum NetBeans
    Réponses: 45
    Dernier message: 13/08/2014, 15h00
  2. Réponses: 0
    Dernier message: 04/10/2012, 15h42
  3. [WD10] Connexion avec l'accès natif MySQL
    Par dj-julio dans le forum WinDev
    Réponses: 5
    Dernier message: 20/02/2012, 12h38
  4. Réponses: 1
    Dernier message: 17/01/2006, 22h56
  5. Connexion depuis LAN impossible vers Mysql sur RH8
    Par RamDevTeam dans le forum Administration
    Réponses: 4
    Dernier message: 10/02/2005, 15h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo