0
votes

I have developed a application using the CodeName One plugin for Java in the Netbeans IDE.

CodeName One uses the 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);

}

I have connected to the Database I created externally using DB Browser for SQLite. I have run the following queries in the DB Browser:

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';

Unfortunately, when I run the code to update the database from my mobile application I get an SQL error:

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)

The name of the Database is correct (connection has been made), however, it won't acknowledge the table.

1
The page you link to shows several overrides of the execute function to execute queries against the database. Did you even read it? - Mark Benningfield

1 Answers

0
votes

I'm assuming the problematic potion is the insert vs. select statement?

You can do an insert with parameters using:

ARdb.execute(query, valueOne, valueTwo);