I am working on my first desktop based Java project. I have 2 questions actually
1) How to perform action on OK button of JOptionPane.showMessageDialog.I want to navigate to a new Jframe say x.java on clicking ok.
2) I have a table named as user. This table has 8 columns userid (Primary Key), name, password,emailid, dob, mobileno ,city, date. Four column entries has to be fetched from a Jframe x and remaining four from other Jframe y.
I wrote the following code
For Frame X
PreparedStatement stm = con.prepareStatement("insert into user
(userrid,name,password,emailid))values (?,?,?,?) ");
stm.setString(1,id); // id is a public variable
stm.setString(2,name);
stm.setString(3,ps);
stm.setString(4,email);
stm.executeUpdate();
And for Frame Y. (userid is primary key)
public class Y extends javax.swing.JFrame
{
X o = new X(); // to access id variable from frame X
}
PreparedStatement stm = con.prepareStatement(" update user set dob ='? ', mobileno
='?' ,city='?', date='?' where userid= 'o.id' ");
It keeps throwing exceptions for the above sql query
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
1) How to perform action on OK button of JOptionPane.showMessageDialog.I want to navigate to a new Jframe say x.java on clicking ok.
int input = JOptionPane.showOptionDialog(null, "Hello World", "The title", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null);
if(input == JOptionPane.OK_OPTION)
{
// do something
}
It keeps throwing exceptions for the above sql query
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
That's because you're using '?'
in Update statement and '
is no needed. You should rewrite like this (assuming you're setting parameters properly):
PreparedStatement stm = con.prepareStatement("UPDATE user SET dob = ?, mobileno = ?, city = ?, date = ? where userid= 'o.id' ");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With