2011-10-03 71 views
0

它没有太多的麻烦,但我从用户点击一个按钮时得到的更新错误。从MySQL转换到SQLite时出错

最初在MySQL中,这是一个枚举('Y','N')值,但由于SQLite没有使用枚举或布尔值,我决定分别使用1和0的整数。

这怎么解决?

if(e.getSource()==boughtB){ 
    String cigName; 
    cigName = Habanos2.selection; 
    String humiString; 
    int humino; 

    Connection con = null; 
    System.out.println(cigName); 

    try{ 
     ResultSet humiRS1 = HabMenu.getGenericRS("select * from cigar where name = '"+cigName+"'"); 
     if(humiRS1.next()){ 
      humiString = humiRS1.getString("humi_no"); 

      humino = Integer.parseInt(humiString); 
      System.out.println("humino"+humino); 

      Class.forName("org.sqlite.JDBC").newInstance(); 

      con = DriverManager.getConnection("jdbc:sqlite:cigardb.db"); 
      Statement s = con.createStatement(); 
      humino++; 
      String humiNoS = Integer.toString(humino); 
      s.executeUpdate("update cigar set humi = 1 where name ='"+cigName+"'"); 
      s.executeUpdate("update cigar set humi_no = "+humiNoS+"where name ='"+cigName+"'"); 

      Habanos2Frame.myHumi.setText(""); 
      ResultSet humiii = HabMenu.getGenericRS("select * from cigar where humi = 1"); 

它产生这样的错误:

java.sql.SQLException: database locked at org.sqlite.DB.execute(DB.java:270) at org.sqlite.DB.executeUpdate(DB.java:281) mysql humi error humiNoS = at org.sqlite.Stmt.executeUpdate(Stmt.java:103) at cigarDiary.buttonBar$ButtonHandler.actionPerformed(buttonBar.java:207) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

+0

您是否尝试过从命令行打开数据库?如果数据库没有正确关闭,它将保持锁定状态,这可能是您收到错误的原因。检查这个其他问题:http://stackoverflow.com/questions/151026/how-do-i-unlock-a-sqlite-database。你可能想阅读关于锁定的SQLite文档:http://www.sqlite.org/lockingv3.html – Augusto

+0

谢谢我认为我让我走上正轨! – Greggg

回答

1

确定我解决,这是通过关闭后我被使用完每个结果集(rs.close)和连接(con.close)的方式。这是MySql似乎并不介意的东西,但SQLite。它不允许你执行更新,而结果集及其连接仍然打开。