We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,420 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

java /= databas

Remove thread double thread occured

3
Contributors
5
Replies
5 Hours
Discussion Span
1 Year Ago
Last Updated
6
Views
TIM_M_91
Junior Poster in Training
83 posts since Feb 2012
Reputation Points: 18
Solved Threads: 0
Skill Endorsements: 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);
            }
        }
  
    }

}
TIM_M_91
Junior Poster in Training
83 posts since Feb 2012
Reputation Points: 18
Solved Threads: 0
Skill Endorsements: 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.

jackbauer24
Posting Whiz in Training
244 posts since Oct 2011
Reputation Points: 21
Solved Threads: 3
Skill Endorsements: 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

TIM_M_91
Junior Poster in Training
83 posts since Feb 2012
Reputation Points: 18
Solved Threads: 0
Skill Endorsements: 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...

peter_budo
Code tags enforcer
Moderator
15,791 posts since Dec 2004
Reputation Points: 2,867
Solved Threads: 944
Skill Endorsements: 50

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) {
               
            }
TIM_M_91
Junior Poster in Training
83 posts since Feb 2012
Reputation Points: 18
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.2970 seconds using 2.67MB