2 Replies - 193 Views - Last Post: 03 April 2013 - 06:33 PM Rate Topic: -----

#1 sirnur  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-January 13

how to store button name text to database based on selections

Posted 03 April 2013 - 03:21 PM

i would like to store the text name of the buttons to database.
the two buttons are called sell and buy i would like to store their text based on the selection of the user.


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);
            }
    }


Is This A Good Question/Topic? 0
  • +

Replies To: how to store button name text to database based on selections

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3458
  • View blog
  • Posts: 11,707
  • Joined: 12-December 12

Re: how to store button name text to database based on selections

Posted 03 April 2013 - 06:04 PM

What is your question? Do you have error messages, which you should post?

However, you have only four parameters (?) in your SQL statement.

Your post is also unclear as to whether you intend to store the names of the buttons, or their text property.

BTW Your inline comments aren't particularly helpful:

    // set input parameter 1
    // set input parameter 2

repeated several times(?).

JFYI Comments like:

pst = conn.prepareStatement(Transaction); // create a statement
// and..
pst.execute();// execute update statement

aren't particularly informative either. Sorry! I don't mean to criticise too much, I just want to point you in the right direction :)/>

This post has been edited by andrewsw: 03 April 2013 - 06:05 PM

Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: how to store button name text to database based on selections

Posted 03 April 2013 - 06:33 PM

I guess this code belongs to an actionPerformed() method

you can always:
JButton b = (Jbutton) e.getSource();
String toPutInBid = b.getText();
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1