1.11M Members

Database Update statement

 
0
 

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());
    }
 
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?

 
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! :)

 
-1
 

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

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: