0

I am receiving this error any time my program is running and I can't figure out what is causing the error. The error is

CheckNList data reading error has occurred java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not update; currently locked by user 'admin' on machine 'PCS'.

The code is shown below. Please seek for your usual help.

public void CheckNList(int SID, int SCOX , int SCOY, int Mission){

        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
            String url = "jdbc:odbc:SENSOR";
            String user = "";
            String pass = "";
            Connection con = DriverManager.getConnection(url,user,pass);
            Statement stmt  = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);                      
            Statement stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);                  
            Statement stmt3 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);              
            int minLevel = -1;
                stmt2.executeUpdate("delete * from NList WHERE ID=" + SID );
                stmt2.executeUpdate("delete * from NList WHERE NID=" + SID);
                ResultSet rs1 = stmt.executeQuery("select * from InerSN where Spower >0 ");
                while(rs1.next()){
                    int NSID = rs1.getInt("SID");
                    int NSCOX = rs1.getInt("SCOX");
                    int NSCOY = rs1.getInt("SCOY");
                    int NSpower = rs1.getInt("Spower");
                    int NLevelNum = rs1.getInt("LevelNum");
                    int Ntempx = NSCOX- SCOX;
                    int Ntempy = NSCOY- SCOY;
                    int NMission = rs1.getInt("Mission");
                    double distance2 = Math.sqrt(Ntempx*Ntempx + Ntempy*Ntempy);
                    if(distance2 <= Parameter.Sensor_Radius && NSID!= SID){
                        if(minLevel==-1 && NLevelNum>0){
                            minLevel = NLevelNum;
                        }else if(minLevel > NLevelNum && NLevelNum>0){
                            minLevel = NLevelNum;
                        }

                        String QueryUpdate13 = "Insert INTO NList(ID,NID,SCOX,SCOY,Spower,LevelNum,Mission) VALUES (" + SID + "," + NSID + "," + NSCOX + "," + NSCOY + "," + NSpower + "," + NLevelNum + "," + NMission +")";

                        stmt3.executeUpdate(QueryUpdate13);

                        String QueryUpdate15 = "select Spower,LevelNum from InerSN where SID=" + SID;
                        ResultSet rs2 = stmt2.executeQuery(QueryUpdate15);
                        while(rs2.next()){    
                            int Spower2   = rs2.getInt("Spower");
                            String QueryUpdate14 = "Insert INTO NList(ID,NID,SCOX,SCOY,Spower,Mission) VALUES (" + NSID + "," + SID + "," + SCOX + "," + SCOY + "," + Spower2 + "," + Mission +")";

                            stmt3.executeUpdate(QueryUpdate14); 
                        }

                    }                   
                }
                if(minLevel==-1){
                    String Queryupdate16 = "Update InerSN SET LevelNum=" + minLevel + " Where SID=" + SID;
                    stmt2.executeUpdate(Queryupdate16);
                    String Queryupdate17 = "Update NList SET LevelNum=" + minLevel + " Where NID=" + SID;
                    stmt2.executeUpdate(Queryupdate17); 
                }else{
                    minLevel = minLevel + 1;
                    String Queryupdate16 = "Update InerSN SET LevelNum=" + minLevel + " Where SID=" + SID;
                    stmt2.executeUpdate(Queryupdate16);
                    String Queryupdate17 = "Update NList SET LevelNum=" + minLevel + " Where NID=" + SID;
                    stmt2.executeUpdate(Queryupdate17);
                }
                stmt3.close();
                stmt2.close();
                stmt.close();
                con.close();
                //System.out.println("DB Disconnect");
            }catch(Exception e){
                System.out.println("CheckNList data reading error has occurred" + e);
            }           //end of catch 
       }    
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
user1304731
  • 25
  • 1
  • 6
  • Hmm, seems you have opened the db file via office access too, close the access application, and have a try :) –  Jul 13 '13 at 19:38
  • The access application is closed. the same happen even if i used another computer – user1304731 Jul 14 '13 at 01:34
  • maybe you add the dns name as read-only!? or the access handler is still exists! try to remove dns name and add it again. –  Jul 14 '13 at 06:01
  • When the application is closed (as well as the .accdb file) is there a lock file in the directory that holds the .accdb file? If so make sure no one else is connected and delete the lock file (.laccdb). See if that works. Sometimes Access forgets to delete its lock file. – Brian.D.Myers Jul 15 '13 at 00:32

0 Answers0