0

A little help guys

i have a JButton..i wanna use it to repeat the SQL statements but with an updated value....

my JButton reads

if(ae.getSource()==b1)
   
      {
   
      v1=v1+2;
   
      System.out.println(v1);
  
      }

v1 gets a new value everytime i click the button

and the v1 is used here ...under public static void main....

Statement s = con.createStatement();
   
      s.execute("SELECT Question FROM Ques WHERE ID=" +v1);

its like i want the question to be displayed...then after clicking b1..the next ques should appear on the same page...

how to go about this? ? ?

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

Put all the code to run the SELECT and update the gui into a single small new method, with the v1 value as a parameter...

public void displayQuestion(int questionID) {
    Statement s = con.createStatement();
    s.execute("SELECT Question FROM Ques WHERE ID=" + questionID);
    // update GUI etc
}

then in your button handler you can say

v1 = v1 + 2;
displayQuestion(v1);

Edited by JamesCherrill: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.