Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Eric Habils
Greenhorn
+ Follow
8
Posts
1
Threads
0
Cows
since Nov 06, 2016
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
Ranch Hand Scavenger Hunt
Number Posts (8/100)
Number Threads Started (1/100)
Number Cows Received (0/5)
Number Likes Received (0/10)
Number Likes Granted (0/20)
Set bumper stickers in profile (0/3)
Report a post to the moderators (0/1)
Edit a wiki page (0/1)
Create a post with an image (0/2)
Greenhorn Scavenger Hunt
First Post
Number Posts (8/10)
Number Threads Started (1/10)
Number Likes Received (0/3)
Number Likes Granted (0/3)
Set bumper stickers in profile (0/1)
Set signature in profile
Search for a post/thread (0/3)
Set a watch on a thread
Save thread as a bookmark
Create a post with an image (0/1)
Recent posts by Eric Habils
Jdbc + Variable j
Hello to all,
I va suppressed
connection conn = null
and replaced
ps.setString(1,"MatriculeToFind");
by
ps.setString(1,MatriculeToFind.getText());
and it seems to run run.
Thanks for all
Habiler
show more
7 years ago
JDBC and Relational Databases
Jdbc + Variable j
at line 28 is the DB connected
show more
7 years ago
JDBC and Relational Databases
Jdbc + Variable j
Now I have a nullPointerException at line ps.setString(1,"MatriculeToFind");
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor0 */ package database; import java.awt.TextField; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; /** * * @author habiler */ public class NewJFrame extends javax.swing.JFrame { private static final long serialVersionUID = 1L; /** * Creates new form NewJFrame */ public NewJFrame() { initComponents(); Connection conn = Connect.ConnectDB(); } /** * This method is called from within the constructor to initialize the form. * 25 * +6 * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { textField1 = new java.awt.TextField(); jTextField1 = new javax.swing.JTextField(); MatriculeToFind = new java.awt.TextField(); MatriculeFinded = new java.awt.TextField(); NomFinded = new java.awt.TextField(); PrenomFinded = new java.awt.TextField(); textField1.setText("textField1"); jTextField1.setText("jTextField1"); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setFont(new java.awt.Font("Cambria", 1, 12)); // NOI18N MatriculeToFind.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { MatriculeToFindMousePressed(evt); } }); MatriculeFinded.setName("MatriculeFinded"); // NOI18N NomFinded.setName(""); // NOI18N PrenomFinded.setName(""); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(52, 52, 52) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(MatriculeToFind, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(MatriculeFinded, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(19, 19, 19) .addComponent(NomFinded, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(PrenomFinded, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(257, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(41, 41, 41) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addComponent(MatriculeToFind, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(54, 54, 54) .addComponent(MatriculeFinded, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(NomFinded, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(PrenomFinded, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(211, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void MatriculeToFindMousePressed(java.awt.event.MouseEvent evt) { Connection conn = null; PreparedStatement ps = null; // validate that idText is a positive int here String MatriculeToFind = null; String SQL = "SELECT Matricule,Nom,Prenom FROM Signaletique WHERE Matricule = ?"; try { ps = conn.prepareStatement(SQL); ps.setString(1,"MatriculeToFind"); ResultSet rs = ps.executeQuery(); while ( rs.next() ) { System.out.println("Matricule"); System.out.println("id"); MatriculeFinded.setText(rs.getString(1)); NomFinded.setText(rs.getString(2)); PrenomFinded.setText(rs.getString(3)); //Display values } ps.close(); } catch (SQLException e) { e.printStackTrace(); } } /** * @param args the command line arguments */ public static void main(String args[]) { /* 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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(NewJFrame.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 NewJFrame().setVisible(true); } }); } // Variables declaration - do not modify private java.awt.TextField MatriculeFinded; private java.awt.TextField MatriculeToFind; private java.awt.TextField NomFinded; private java.awt.TextField PrenomFinded; private javax.swing.JTextField jTextField1; private java.awt.TextField textField1; // End of variables declaration }
show more
7 years ago
JDBC and Relational Databases
Jdbc + Variable j
My error is on line rs.getString(1,MatriculeToFind);
/* /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor0 */ package database; import java.awt.TextField; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; /** * * @author habiler */ public class NewJFrame extends javax.swing.JFrame { private static final long serialVersionUID = 1L; /** * Creates new form NewJFrame */ public NewJFrame() { initComponents(); Connection conn = Connect.ConnectDB(); } /** * This method is called from within the constructor to initialize the form. * 25 * +6 * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { textField1 = new java.awt.TextField(); jTextField1 = new javax.swing.JTextField(); MatriculeToFind = new java.awt.TextField(); MatriculeFinded = new java.awt.TextField(); NomFinded = new java.awt.TextField(); PrenomFinded = new java.awt.TextField(); textField1.setText("textField1"); jTextField1.setText("jTextField1"); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setFont(new java.awt.Font("Cambria", 1, 12)); // NOI18N MatriculeToFind.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { MatriculeToFindMousePressed(evt); } }); MatriculeFinded.setName("MatriculeFinded"); // NOI18N NomFinded.setName(""); // NOI18N PrenomFinded.setName(""); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(52, 52, 52) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(MatriculeToFind, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(MatriculeFinded, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(19, 19, 19) .addComponent(NomFinded, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(PrenomFinded, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(257, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(41, 41, 41) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addComponent(MatriculeToFind, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(54, 54, 54) .addComponent(MatriculeFinded, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(NomFinded, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(PrenomFinded, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(211, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void MatriculeToFindMousePressed(java.awt.event.MouseEvent evt) { Connection conn = null; PreparedStatement ps = null; // validate that idText is a positive int here //String MatriculeToFind = null; String SQL = "SELECT Matricule,Nom,Prenom FROM Signaletique WHERE Matricule = ?"; try { conn = Connect.ConnectDB(); ps = conn.prepareStatement(SQL); ResultSet rs = ps.executeQuery(); { [u] rs.getString(1,MatriculeToFind);[/u][b][/b] System.out.println("Matricule"); if ( rs.next() ) { MatriculeFinded.setText(rs.getString(1)); NomFinded.setText(rs.getString(2)); PrenomFinded.setText(rs.getString(3)); //Display values } } ps.close(); } catch (SQLException e) { e.printStackTrace(); } } /** * @param args the command line arguments */ public static void main(String args[]) { /* 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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(NewJFrame.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 NewJFrame().setVisible(true); } }); } // Variables declaration - do not modify private java.awt.TextField MatriculeFinded; private java.awt.TextField MatriculeToFind; private java.awt.TextField NomFinded; private java.awt.TextField PrenomFinded; private javax.swing.JTextField jTextField1; private java.awt.TextField textField1; // End of variables declaration }
Error :
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.5 Parameter not set at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeQuery(UcanaccessPreparedStatement.java:241) at database.NewJFrame.MatriculeToFindMousePressed(NewJFrame.java:116) at database.NewJFrame.access$000(NewJFrame.java:18) at database.NewJFrame$1.mousePressed(NewJFrame.java:57) at java.awt.Component.processMouseEvent(Component.java:6530) at java.awt.Component.processEvent(Component.java:6298) at java.awt.TextComponent.processEvent(TextComponent.java:673) at java.awt.TextField.processEvent(TextField.java:588) at java.awt.Component.dispatchEventImpl(Component.java:4889) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.awt.EventQueue$4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) Caused by: java.sql.SQLException: Parameter not set at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCPreparedStatement.checkParametersSet(Unknown Source) at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source) at org.hsqldb.jdbc.JDBCPreparedStatement.executeQuery(Unknown Source) at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeQuery(UcanaccessPreparedStatement.java:239) ... 27 more Caused by: org.hsqldb.HsqlException: Parameter not set at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.error.Error.error(Unknown Source) ... 32 more
show more
7 years ago
JDBC and Relational Databases
Jdbc + Variable j
Now its give me an error at
String idText = MatriculeToFind.getText();
String
private void MatriculeToFindMousePressed(java.awt.event.MouseEvent evt) { Connection conn = null; PreparedStatement ps = null; String idText = MatriculeToFind.getText(); // validate that idText is a positive int here int id = Integer.parseInt(idText); String SQL = "SELECT Matricule,Nom,Prenom FROM Signaletique WHERE Matricule = ?"; try { conn = Connect.ConnectDB(); ps = conn.prepareStatement(SQL); ResultSet rs =ps.executeQuery(); { ps.setInt(1, id); System.out.println(id); while( rs.next() ) { MatriculeFinded.setText(rs.getString(1)); NomFinded.setText(rs.getString(2)); PrenomFinded.setText(rs.getString(3)); //Display values } } ps.close(); } catch (SQLException e) { e.printStackTrace(); } }
show more
7 years ago
JDBC and Relational Databases
Jdbc + Variable j
I ve supressed the toString and replaced the ""String"" by int but no changes
Where do I filling the variable MatriculeToFind ?
Habiler
show more
7 years ago
JDBC and Relational Databases
Jdbc + Variable j
The textFields MatriculeFinded and NameFinded are empty< But when i replace the ? by a valid id number its ok
thanks
show more
7 years ago
JDBC and Relational Databases
Jdbc + Variable j
Hi the Community,
I have a jframe with 3 textfields>
MatriculeToFind
MatriculeFinded
Name
The target is when I introduce id number in MatriculeTofind the program insert the id and the name into MatriculeFinded and nameFinded.
But in the program the result is null.
where is my error.
Thanks
Habiler
private void MatriculeToFindMousePressed(java.awt.event.MouseEvent evt) { Connection conn = null; PreparedStatement prepStmt = null; String MatriculeToFind = null; String SQL = "SELECT Matricule,Nom,Prenom FROM Signaletique WHERE Matricule = ?"; try { conn = Connect.ConnectDB(); prepStmt = conn.prepareStatement(SQL); prepStmt.setString(1, "MatriculeToFind".toString()); ResultSet rs = prepStmt.executeQuery(); { while( rs.next() ) { MatriculeFinded.setText(rs.getString(1)); NomFinded.setText(rs.getString(2)); PrenomFinded.setText(rs.getString(3)); //Display values } } prepStmt.close(); } catch (SQLException e) { e.printStackTrace(); } }
show more
7 years ago
JDBC and Relational Databases