这并没有太大麻烦,但我不断从用户单击按钮的更新中收到错误。
最初在 MySQL 中这是一个 enum('Y','N') 值,但由于 SQLite 不使用枚举或 boolean 值,我决定分别使用带有 1 和 0 的 int。
如何解决这个问题?
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)
最佳答案
好吧,我解决这个问题的方法是在使用完每个结果集(rs.close)和连接(con.close)后关闭它。 MySql 似乎不介意这一点,但 SQLite 却介意。当结果集及其连接仍然打开时,它不允许您执行更新。
关于java - 从 MySQL 转换到 SQLite 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7633330/