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.

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

Got it working now but thanks for replies

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