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

Database Update statement

Hi guys well I have successfully got my update query to work correctly. Now I have two tables in my database. What I want to do is when I click my play button not only does it update my column's in my first table but all updates my colunms in my second table if the values from my first table exist in my second table. So my question is what would I need to change or add to the following code:

if (e.getSource() == PLAY) {
          
      
             String p = PLAYLIST.getText();
             
               Connection con = null;
    try {
      con = DriverManager.getConnection(
        "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=VIDEODB1.mdb;");
      Statement sta = con.createStatement(); 
      int c = sta.executeUpdate("UPDATE " + p + " SET PLAYCOUNT = PLAYCOUNT + 1");
int d = sta.executeUpdate("UPDATE TABLE2 SET PLAYCOUNT = PLAYCOUNT + 1");
      sta.close();
      con.close();        
    } catch (Exception I) {
      System.err.println("Exception: "+I.getMessage());
    }
2
Contributors
3
Replies
2 Days
Discussion Span
1 Year Ago
Last Updated
7
Views
TIM_M_91
Junior Poster in Training
83 posts since Feb 2012
Reputation Points: 18
Solved Threads: 0
Skill Endorsements: 0

Can someone tell me why this code produces no errors but does not update my fields:

try {
      con = DriverManager.getConnection(
        "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=VIDEODB1.mdb;");
      Statement sta = con.createStatement(); 
      int c = sta.executeUpdate("UPDATE VIDEOS INNER JOIN PLAYLIST ON VIDEOS.PLAYCOUNT = PLAYLIST.PLAYCOUNT SET VIDEOS.PLAYCOUNT = PLAYLIST.PLAYCOUNT");
      
  
      
      
      

      sta.close();
      con.close();        
    } catch (Exception I) {
      System.err.println("Exception: "+I.getMessage());
    }

What I want this code to do is get information from the colunm PLAYCOUNT in PLAYLIST and produce it in VIDEOS to the correct video through its VIDEOID. At the moment no video is being affected.

Any help?

TIM_M_91
Junior Poster in Training
83 posts since Feb 2012
Reputation Points: 18
Solved Threads: 0
Skill Endorsements: 0

I recommend that you check out your SQL statement once, and get sure of it's correctness. Also, how are you checking whether/not the fields have been updated? That'll help me in solving your problem better! :)

dantinkakkar
Junior Poster
177 posts since Aug 2011
Reputation Points: 49
Solved Threads: 22
Skill Endorsements: 4

I recommend that you check out your SQL statement once, and get sure of it's correctness. Also, how are you checking whether/not the fields have been updated? That'll help me in solving your problem better! :)

I have two table called VIDEOS and PLAYLIST in VIDEOS the colunms are ID,NAME,DIRECTOR, and PLAYCOUNT. In PLAYLIST colunms are ID,VIDEONAME, and PLAYCOUNT. When I execute the query above nothing occurs in either tables

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 generated in 0.0608 seconds using 2.66MB