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

JDBC Java Discussion :

Pb rs.getString avec JDBC dans fonction insert into


Sujet :

JDBC Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    470
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2009
    Messages : 470
    Par défaut Pb rs.getString avec JDBC dans fonction insert into
    Bonjour la communaute.

    J'ai un probleme au niveau du
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    rs.setString(1, ((JTextField)jDCDebut.getDateEditor().getUiComponent()).getText());
    Mais pas de commentaires d'erreurs au niveau du debug et du run file.
    Quelqu'un pourrait-il maider svp
    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
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
     
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JTextField;
    import javax.swing.UnsupportedLookAndFeelException;
     
     
    public class AddData extends javax.swing.JFrame {
    //Date sDate = null; 
        public AddData() {
     
     
        }
     
     
      public static void connection(){
            try {
             Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");   
            }catch (ClassNotFoundException e){
        }
        }   
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            fldDos_Id = new java.awt.TextField();
            lblDos_Id = new java.awt.Label();
            fldMatricule = new java.awt.TextField();
            lblMatricule = new java.awt.Label();
            lblDébut = new java.awt.Label();
            jDCDebut = new com.toedter.calendar.JDateChooser();
            btSubmit = new javax.swing.JButton();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            fldDos_Id.setText("Dossier Id");
     
            lblDos_Id.setText("N° Dossier");
     
            fldMatricule.setPreferredSize(new java.awt.Dimension(60, 20));
            fldMatricule.setText("Matricule");
     
            lblMatricule.setText("Matricule");
     
            lblDébut.setText("Début absence");
     
            btSubmit.setText("Submit");
            btSubmit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btSubmitActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(93, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(btSubmit, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(lblMatricule, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(fldMatricule, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lblDébut, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(lblDos_Id, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(24, 24, 24)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(fldDos_Id, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jDCDebut, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                            .addGap(127, 127, 127))))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(67, 67, 67)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblDos_Id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(fldDos_Id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblMatricule, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(fldMatricule, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblDébut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jDCDebut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(52, 52, 52)
                    .addComponent(btSubmit)
                    .addContainerGap(78, Short.MAX_VALUE))
            );
     
            pack();
        }// </editor-fold>                        
     
        private void btSubmitActionPerformed(java.awt.event.ActionEvent evt) {                                         
      try 
      {
          String sql = "jdbc:ucanaccess://C:\\Users\\ehabi\\OneDrive\\Documents\\Decisions_2019.accdb";
     
          Connection conn=DriverManager.getConnection(sql,"","");
        //  Statement stmt=conn.createStatement();
          ResultSet rs = conn.createStatement().executeQuery("insert into Beslissing (Debut) Values (?)");
     
          try
          {
              while (rs.next()) {
                   rs.setString(1, ((JTextField)jDCDebut.getDateEditor().getUiComponent()).getText());
              }
              rs.close();
              conn.close();
          }
          catch (SQLException e)
          {
              System.out.println("Error in fetching data" + e);
          }        // TODO add your handling code here:
      }
        catch (SQLException ex) 
      {
            Logger.getLogger(AddData.class.getName()).log(Level.SEVERE, null, ex);
      }        // TODO add your handling code here:
        }                                        
     
        /**
         * @param args the command line arguments
         * @throws java.lang.InstantiationException
         * @throws java.lang.IllegalAccessException
         * @throws javax.swing.UnsupportedLookAndFeelException
         */
        public static void main(String args[]) throws InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(AddData.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } 
            //</editor-fold>
     
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new AddData().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify                     
        private javax.swing.JButton btSubmit;
        private java.awt.TextField fldDos_Id;
        private java.awt.TextField fldMatricule;
        private com.toedter.calendar.JDateChooser jDCDebut;
        private java.awt.Label lblDos_Id;
        private java.awt.Label lblDébut;
        private java.awt.Label lblMatricule;
        // End of variables declaration                   
    }

  2. #2
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2018
    Messages
    80
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2018
    Messages : 80
    Par défaut
    Bonjour,

    Je pense que vous confondez l'objet ResultSet et l'objet PreparedStatement.
    De la documentation :


    Utilisez l'objet PreparedStatement.

    Bon courage

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

Discussions similaires

  1. Problème dans la fonction INSERT INTO
    Par had4789 dans le forum Excel
    Réponses: 2
    Dernier message: 21/06/2014, 20h42
  2. id créer avec exception dans fonction
    Par gKsam dans le forum Requêtes
    Réponses: 7
    Dernier message: 02/11/2010, 14h53
  3. Appel de fonction avec parametre dans fonction
    Par VooDooNet dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 03/05/2010, 18h40
  4. [SQL] SQL syntax error dans fonction insert into
    Par scarfesse dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 21/12/2007, 13h25
  5. probleme avec jdbc dans un prog Java
    Par 18Marie dans le forum JDBC
    Réponses: 5
    Dernier message: 17/07/2006, 09h40

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