我的程序运行时,我收到此错误,我无法弄清楚导致错误的原因。错误是
CheckNList数据读取错误已发生java.sql.SQLException:[Microsoft] [ODBC Microsoft Access Driver]无法更新;目前由机器'PCS'上的用户'admin'锁定。
代码如下所示。请寻求你的平常帮助。
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
}