Ms access JDBC Microsoft access更新错误

Ms access JDBC Microsoft access更新错误,ms-access,jdbc-odbc,Ms Access,Jdbc Odbc,每当我的程序运行时,我都会收到这个错误,我无法找出是什么导致了这个错误。错误是 发生CheckNList数据读取错误java.sql.SQLException:[Microsoft][ODBC Microsoft Access驱动程序]无法更新;当前由计算机“PC”上的用户“管理员”锁定 代码如下所示。请寻求你平时的帮助 public void CheckNList(int SID, int SCOX , int SCOY, int Mission){ try{

每当我的程序运行时,我都会收到这个错误,我无法找出是什么导致了这个错误。错误是

发生CheckNList数据读取错误java.sql.SQLException:[Microsoft][ODBC Microsoft Access驱动程序]无法更新;当前由计算机“PC”上的用户“管理员”锁定

代码如下所示。请寻求你平时的帮助

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 
       }    
public void CheckNList(int-SID、int-SCOX、int-SCOY、int-Mission){
试一试{
forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
String url=“jdbc:odbc:SENSOR”;
字符串user=“”;
字符串pass=“”;
Connection con=DriverManager.getConnection(url、用户、通行证);
语句stmt=con.createStatement(ResultSet.TYPE\u SCROLL\u敏感,ResultSet.CONCUR\u可更新);
语句stmt2=con.createStatement(ResultSet.TYPE\u SCROLL\u敏感,ResultSet.CONCUR\u可更新);
语句stmt3=con.createStatement(ResultSet.TYPE\u SCROLL\u敏感,ResultSet.CONCUR\u可更新);
int minLevel=-1;
stmt2.executeUpdate(“从NList中删除*,其中ID=“+SID”);
stmt2.executeUpdate(“从NList中删除*,其中NID=“+SID”);
ResultSet rs1=stmt.executeQuery(“从InerSN中选择*,其中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(“任务”);
双距离2=数学sqrt(Ntempx*Ntempx+Ntempy*Ntempy);
如果(距离2 0){
minLevel=NLevelNum;
}else if(minLevel>NLevelNum&&NLevelNum>0){
minLevel=NLevelNum;
}
String QueryUpdate13=“将值(“+SID+”、“+NSID+”、“+NSCOX+”、“+NSCOY+”、“+NSpower+”、“+NLEVELENUM+”、“+NMission+”)插入NList(ID、NID、SCOX、SCOY、Spower、LevelNum、Mission)列表中”;
stmt3.executeUpdate(QueryUpdate13);
String QueryUpdate15=“从InerSN中选择Spower,LevelNum,其中SID=“+SID;
结果集rs2=stmt2.executeQuery(查询更新15);
而(rs2.next()){
int Spower2=rs2.getInt(“Spower”);
字符串QueryUpdate14=“插入NList(ID、NID、SCOX、SCOY、Spower、Mission)值(“+NSID+”、“+SID+”、“+SCOX+”、“+SCOY+”、“+Spower2+”、“+Mission+”);
stmt3.executeUpdate(QueryUpdate14);
}
}                   
}
如果(最小级别==-1){
字符串Queryupdate16=“更新InerSN SET LevelNum=“+minLevel+”,其中SID=“+SID;
stmt2.executeUpdate(Queryupdate16);
字符串Queryupdate17=“更新NList SET LevelNum=“+minLevel+”,其中NID=“+SID;
stmt2.executeUpdate(Queryupdate17);
}否则{
minLevel=minLevel+1;
字符串Queryupdate16=“更新InerSN SET LevelNum=“+minLevel+”,其中SID=“+SID;
stmt2.executeUpdate(Queryupdate16);
字符串Queryupdate17=“更新NList SET LevelNum=“+minLevel+”,其中NID=“+SID;
stmt2.executeUpdate(Queryupdate17);
}
stmt3.close();
stmt2.close();
stmt.close();
con.close();
//System.out.println(“DB断开”);
}捕获(例外e){
System.out.println(“发生校验列表数据读取错误”+e);
}//捕获结束
}    

Hmm,似乎您也通过office access打开了db文件,请关闭access应用程序,然后再试一次:)access应用程序已关闭。同样的情况也会发生,即使我使用了另一台计算机,也许你将dns名称添加为只读!?或者访问处理程序仍然存在!尝试删除dns名称并再次添加。当应用程序关闭(以及.accdb文件)时,目录中是否有保存.accdb文件的锁定文件?如果是,请确保没有其他人连接并删除锁文件(.laccdb)。看看这是否有效。有时Access会忘记删除其锁定文件。