Hi Guys well what I want to do is instead of within my writeString to set my PLAYCOUNT to '16' what I want to do is every time the statement is executed my PLAYCOUNT is increased by 1.

Any help you can give would be appreciated:

My code is below:

if (e.getSource() == writeBtn) {
            String f = VIDEOID.getText();
            String v = VIDEONAME.getText();
            String s = DIRECTOR.getText();
             String r = RATING.getText();
             String p = PLAYCOUNT.getText();
            // if any field is blank, signal an error
           
            String writeString =
                    "UPDATE VIDEOS SET PLAYCOUNT = '16' WHERE VIDEOID = '1'";
            try {
                myStatement.executeUpdate(writeString);
                VIDEONAME.setText("");
                DIRECTOR.setText("");
                RATING.setText("");
                PLAYCOUNT.setText("");
            } catch (SQLException sqle) {
                Toolkit.getDefaultToolkit().beep();
                showMessageDialog(this, "Wrong Data Type");
            }
             VIDEOID.setText("");
        }

Convert Write String to a function which takes int as a parameter and returns the String to execute.
Let me explain more

method String writeString(int)
{
return Here is ur code
}

Declare a variable locally increment it and send to function.

Edited 4 Years Ago by Majestics: n/a

Hi Guys well what I want to do is instead of within my writeString to set my PLAYCOUNT to '16' what I want to do is every time the statement is executed my PLAYCOUNT is increased by 1.

Any help you can give would be appreciated:

My code is below:

if (e.getSource() == writeBtn) {
            String f = VIDEOID.getText();
            String v = VIDEONAME.getText();
            String s = DIRECTOR.getText();
             String r = RATING.getText();
             String p = PLAYCOUNT.getText();
            // if any field is blank, signal an error
           
            String writeString =
                    "UPDATE VIDEOS SET PLAYCOUNT = '16' WHERE VIDEOID = '1'";
            try {
                myStatement.executeUpdate(writeString);
                VIDEONAME.setText("");
                DIRECTOR.setText("");
                RATING.setText("");
                PLAYCOUNT.setText("");
            } catch (SQLException sqle) {
                Toolkit.getDefaultToolkit().beep();
                showMessageDialog(this, "Wrong Data Type");
            }
             VIDEOID.setText("");
        }

well depends, but in java

PlayCount++;

would increment the integer PlayCount +1... however i see play count is initialized as string.... so what do you mean by incrementing a string by 1....

Edited 4 Years Ago by DavidKroukamp: n/a

Got it working now but thanks for replies

Edited 4 Years Ago by TIM_M_91: n/a

Hi guys got a problem which is that I have successfully set up a counter that when a button is pressed adds a value to my database. However my problem is that when the when the button is pressed it adds up values fine but if I close the program and reopen it it will start the counter from zero again. Therefore what do I need to do to the following code that will read the number already in the table and start the counter from that number instead of each time resetting the counter:


Any help would be appriciated

Code is below:

public class test extends JFrame implements ActionListener {

    
    int button1count = 0;


}
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == writeBtn) {
            String f = VIDEOID.getText();
            String v = VIDEONAME.getText();
            String s = DIRECTOR.getText();
             String r = RATING.getText();
             String p = PLAYCOUNT.getText();
            
            
           
             button1count++;
            
             
             
             // if any field is blank, signal an error
           
             
             String writeString1 =
                     "SELECT FROM VIDEOS PLAYCOUNT WHERE VIDEOID = 1";
             
            
             
             
             
             String writeString =
                     "UPDATE VIDEOS SET PLAYCOUNT = '" + button1count +"' WHERE VIDEOID = '1'";
            try {
                myStatement.executeUpdate(writeString);
                myStatement.executeUpdate(writeString1);
                VIDEONAME.setText("");
                DIRECTOR.setText("");
                RATING.setText("");
              
            } catch (SQLException sqle) {
                Toolkit.getDefaultToolkit().beep();
                showMessageDialog(this, "Wrong Data Type");
            }
           
        }
    
    }
}

Edited 4 Years Ago by TIM_M_91: n/a

This article has been dead for over six months. Start a new discussion instead.