【发布时间】:2019-05-31 06:59:16
【问题描述】:
我想检索从组合框中选择的值到 jtextfield。根据我的 UI 组合框位于第 4 位。所以我编码:
pst.setString(4, (String)cmbPaySub.getSelectedItem());
和错误弹出:
参数索引超出范围。(4>参数个数,即1"。
我尝试过编码;
pst.setString(1, (String)cmbPaySub.getSelectedItem());
既不会弹出错误,也不会出现值。
private void cmbPaySubActionPerformed(java.awt.event.ActionEvent evt) {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sipnena", "root", "");
String sql="select * from payments where cmbSubject=?";
PreparedStatement pst=con.prepareStatement(sql);
pst.setString(4, (String)cmbPaySub.getSelectedItem());
ResultSet rs=pst.executeQuery();
while(rs.next()){
txtFee.setText(rs.getString("Fee"));
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
请帮助我检索 jtextfield 的值。
【问题讨论】:
-
pst.setString(4它的pst.setString(1索引位置将从1开始。 -
嗨,我也编码为 1。但什么也没发生
-
意味着出现同样的错误?
-
您想从 cmbPaySub 接收数据到 txtFee?如果它是正确的,那不是你的代码的意思
-
SatyaTNV 不是错误。也没有获得价值。