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

java + database

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

Well... If it is an Oracle database,
You could have a BEFORE UPDATE trigger in the database.

hfx642
Posting Pro
515 posts since Nov 2009
Reputation Points: 248
Solved Threads: 105
Skill Endorsements: 1

Have you tried the obvious
SET PLAYCOUNT = PLAYCOUNT + 1
... seems to work in ordinary SQL

JamesCherrill
... trying to help
Moderator
8,683 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,479
Skill Endorsements: 33

Have you tried the obvious
SET PLAYCOUNT = PLAYCOUNT + 1
... seems to work in ordinary SQL

Solved it but thanks for reply code I used was:

int c = sta.executeUpdate("UPDATE VIDEOS SET PLAYCOUNT = PLAYCOUNT + 1 WHERE VIDEOID = '"+ v + "'");
TIM_M_91
Junior Poster in Training
83 posts since Feb 2012
Reputation Points: 18
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by JamesCherrill and hfx642

This question has already been solved: Start a new discussion instead

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