Mal*_*eek 5 java mysql swing jdbc joptionpane
我正在研究我的第一个基于桌面的Java项目.我实际上有两个问题
1)如何对JOptionPane.showMessageDialog的OK按钮执行操作.我想在单击确定时导航到新的Jframe说x.java.
2)我有一个名为user的表.此表有8列userid(主键),名称,密码,emailid,dob,mobileno,city,date.必须从Jframe x中获取四个列条目,而从其他Jframe y中获取四个列条目.
我写了以下代码
对于第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();
Run Code Online (Sandbox Code Playgroud)
对于帧Y.(userid是主键)
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' ");
Run Code Online (Sandbox Code Playgroud)
它不断抛出上述sql查询的异常
java.sql.SQLException:参数索引超出范围(1>参数个数,为0).
Eng*_*uad 15
1)如何对JOptionPane.showMessageDialog的OK按钮执行操作.我想在单击确定时导航到新的Jframe说x.java.
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
}
Run Code Online (Sandbox Code Playgroud)