我在Netbeans IDE中使用CodeName One Java插件开发了一个应用程序。
CodeName One使用Database API。 https://www.codenameone.com/javadoc/com/codename1/db/Database.html
Database db = null;
Cursor cur = null;
String Fname = findTxtFirstn(c).getText();
String Lname = findTxtLastn(c).getText();
try{
Database ARdb = Display.getInstance().openOrCreate("RecordsDB.db");
System.out.println("Connection secured to database.");
String query = "insert into RecordsTable (First_Name,Last_Name) values (Fname,Lname)";
ARdb.execute(query);
} catch(Exception e){
System.out.println("Error! Connection Failed to DB" +e.getMessage());
} finally {
Util.cleanup (db);
Util.cleanup(cur);
}
我已连接到我使用DB Browser for SQLite在外部创建的数据库。我在数据库浏览器中运行了以下查询:
PRAGMA foreign_keys = "1";
SELECT type,name,sql,tbl_name,'0' AS temp FROM sqlite_master UNION SELECT type,name,sql,tbl_name,'1' AS temp FROM sqlite_temp_master;
PRAGMA encoding
SELECT COUNT(*) FROM (SELECT `_rowid_`,* FROM `RecordsTable` ORDER BY `_rowid_` ASC);
SELECT `_rowid_`,* FROM `RecordsTable` ORDER BY `_rowid_` ASC LIMIT 0, 50000;
SELECT COUNT(*) FROM (SELECT `_rowid_`,* FROM `RecordsTable` ORDER BY `_rowid_` ASC);
SELECT `_rowid_`,* FROM `RecordsTable` ORDER BY `_rowid_` ASC LIMIT 0, 50000;
INSERT INTO `RecordsTable`(`ID`,`First_Name`,`Last_Name`,`Phone`,`Email`,`Street`,`Town`,`Postcode`,`Dog_Name`,`Breed`,`Age`,`Gender`,`BIO`) VALUES (1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
UPDATE `RecordsTable` SET `First_Name`=? WHERE _rowid_='1';
UPDATE `RecordsTable` SET `Last_Name`=? WHERE _rowid_='1';
PRAGMA foreign_keys
SELECT COUNT(*) FROM (SELECT `_rowid_`,* FROM `RecordsTable` ORDER BY `_rowid_` ASC);
SELECT `_rowid_`,* FROM `RecordsTable` ORDER BY `_rowid_` ASC LIMIT 0, 50000;
SELECT COUNT(*) FROM (SELECT `_rowid_`,* FROM `RecordsTable` ORDER BY `_rowid_` ASC);
SELECT `_rowid_`,* FROM `RecordsTable` ORDER BY `_rowid_` ASC LIMIT 0, 50000;
UPDATE `RecordsTable` SET `Phone`=? WHERE _rowid_='1';
UPDATE `RecordsTable` SET `First_Name`=? WHERE _rowid_='1';
UPDATE `RecordsTable` SET `Phone`=? WHERE _rowid_='1';
UPDATE `RecordsTable` SET `Email`=? WHERE _rowid_='1';
UPDATE `RecordsTable` SET `Street`=? WHERE _rowid_='1';
UPDATE `RecordsTable` SET `Town`=? WHERE _rowid_='1';
UPDATE `RecordsTable` SET `Postcode`=? WHERE _rowid_='1';
不幸的是,当我运行代码从我的移动应用程序更新数据库时,我收到一个SQL错误:
Connection secured to database.
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: RecordsTable)
Error! Connection Failed to DB[SQLITE_ERROR] SQL error or missing database (no such table: RecordsTable)
数据库的名称是正确的(已建立连接),但是,它不会确认该表。
答案 0 :(得分:0)
我假设有问题的药水是插入与选择语句?
您可以使用以下参数插入参数:
ARdb.execute(query, valueOne, valueTwo);