0

我正在尝试获取所选按钮的文本名称并将其发送到我的数据库。buttonGroup 是否有办法传递所选按钮名称的文本?因为我想将选定的按钮名称插入到事务表中

 try {
      conn = getConnection(); 
      String Transaction = "INSERT  INTO Transaction"
                + "(Currency_type, currency_Amount,Local_Amount,Rate,Tran_type) VALUES"
                + "(?,?,?,?)";

      pst = conn.prepareStatement(Transaction); // create a statement
      pst.setObject(1,DisplayL.getText()); // set input parameter 1
      pst.setObject(2,txt_select.getText()); // set input parameter 2
      pst.setObject(3,txt_amount.getText()); // set input parameter 1
      pst.setObject(4,txt_rate.getText()); // set input parameter 2
      pst.setObject(5,buttonGroup2); // set input parameter 2

      pst.execute();// execute update statement
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
            try {
                pst.close();
            } catch (SQLException ex) {
                Logger.getLogger(connectnm.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(connectnm.class.getName()).log(Level.SEVERE, null, ex);
            }
    }

预期产出

交易

Tran_ID  |Currency_type | currency_Amount|  Local_Amount|   Rate  |Tran_type|
     4   | Euro         |  1200.00       |    1000.00   |   1.120 |**Sell** |
4

1 回答 1

1
 ButtonModel btnModel = buttonGroup2.getSelection();
if(btnModel !=null)
{
 btnModel.getActionCommand()
}
于 2013-04-03T15:11:33.627 回答