1,105,592 Community Members

java /= databas

Member Avatar
TIM_M_91
Junior Poster in Training
92 posts since Feb 2012
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Remove thread double thread occured

Member Avatar
TIM_M_91
Junior Poster in Training
92 posts since Feb 2012
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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);
            }
        }
  
    }

}
Member Avatar
jackbauer24
Posting Whiz in Training
243 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
TIM_M_91
Junior Poster in Training
92 posts since Feb 2012
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
peter_budo
Code tags enforcer
7,939 posts since Dec 2004
Reputation Points: 2,502 [?]
Q&As Helped to Solve: 1,028 [?]
Skill Endorsements: 66 [?]
Moderator
Featured
 
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...

Member Avatar
TIM_M_91
Junior Poster in Training
92 posts since Feb 2012
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: