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? ? ?

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.