1.11M Members

java /= databas

 
0
 

Remove thread double thread occured

 
0
 

Hi guys what I want to do is when my play button is pressed is read my PLAYCOUNT from my database and then the counter adds a value onto the PLAYCOUNT pre existing value then saves the value into the database. If I then close the program the counter will start from the new value. Therefore how do I do this?

My code can be seen below:

int counter;
    

    public void actionPerformed(ActionEvent e) {
        
        
         if (e.getSource() == play) { // if list button is pressed following statement will take place
         String v = videoNo.getText();
             counter++;
             String writeString =
                     "UPDATE VIDEOS SET PLAYCOUNT = '" + counter +"' WHERE VIDEOID = '"+ v + "'";
            try {
                myStatement.executeUpdate(writeString);
            } catch (SQLException sqle) {
               
            }
        try {
                ResultSet results = myStatement.executeQuery
                        ("SELECT * FROM VIDEOS WHERE VIDEOID = '1' ");
                while (results.next()) {
                    out.append(results.getString(5) + " ");

                }
                
                results.close();
            } catch (SQLException sqle) {
                out.println(sqle);
            }
        }
  
    }

}
 
0
 

What do you mean a "double thread" occurred? On Daniweb, there is no such thing as a double thread.
Also, with it's excellent systems, a duplicate thread cannot be made by mistake.
Plus the titles are different.

 
0
 

What do you mean a "double thread" occurred? On Daniweb, there is no such thing as a double thread.
Also, with it's excellent systems, a duplicate thread cannot be made by mistake.
Plus the titles are different.

I edited title

 
0
 

Threads merged. Please stop messing around with creation of new threads just because you wanted change thread title. Secondly many of this thread should stay with original question as they are only update on the work you do...

 
0
 

Hi there guys can someone explain to me how I can increment a value within a field in my database each time I execute my query?. As I cannot seem to find a way to do this. Below is my structure for reading + writting to my database if you need it to help me with my problem.

Also the code below updates my selected column but each time sets my playcount back to '1'. I wish to each time add 1 to the existing value. For instance if the value was already 1 when the query is executed the value becomes 2.


Any help would be appreciated

Code below:

String v = videoNo.getText();
            
             String writeString =
                     "UPDATE VIDEOS SET PLAYCOUNT = '1' WHERE VIDEOID = '"+ v + "'";
            try {
                myStatement.executeUpdate(writeString);
            } catch (SQLException sqle) {
               
            }
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: