SQLite-没有错误,但是,没有数据上传到数据库 [英] SQLite - no errors, however, no data uploaded to DB

查看:65
本文介绍了SQLite-没有错误,但是,没有数据上传到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Netbeans IDE中使用Java的CodeName One插件开发了一个移动应用程序。

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

CodeName One使用数据库API。 https://www.codenameone.com/javadoc/com/codename1/ db / Database.html

CodeName One uses the Database API. https://www.codenameone.com/javadoc/com/codename1/db/Database.html

我正在运行一些测试(我想上传大约10个值,不过,仅通过以下方式测试连接

I'm running some tests (there are around 10 values I would like to upload, however, just testing the connection ect by uploading ID, Fname and Lname values.

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.");

            ARdb.beginTransaction();

            String createTable = "CREATE TABLE IF NOT EXISTS RecordsTable ("
                    + "ID integer PRIMARY KEY,"
                    + "First_Name text NOT NULL,"
                    + "Last_Name text NOT NULL)";

            String query = "insert into RecordsTable (ID,First_Name,Last_Name) values (3,'Test','Testerton')";       

            ARdb.execute(createTable);
            ARdb.execute(query);

            ARdb.commitTransaction();  

        } catch(Exception e){

            System.out.println("Error! Connection Failed to DB" +e.getMessage());

        } finally {

            Util.cleanup (db);
            Util.cleanup(cur);

        }

我没有错误,一切都在运行,但是值当我检查它时不在数据库中。我在这里想念什么吗?我按照教程学习了Codename One API。我找不到解决方案。

I get no errors and everything runs, however, the values are not in the database when I check it. Am I missing something here? I have followed tutorials and looked over the Codename One API. I can't find the solution.

编辑:每次运行时我都需要更改主数的值(否则我会得到一个错误:数字必须唯一) ,这告诉我值正在存储在数据库中,不幸的是,当我检查有问题的数据库时,上面没有记录,因此数据将流向何处?

I need to change the value of the primary number each run (else I get an error: number needs to be unique), This tells me the values are being stored on the database, unfortunately, when I check the database in question there are no records on it, so where it the data going?

我将数据库浏览器用于SQLite。

I used DB Browser for SQLite.

推荐答案

您是否尝试过在事务中执行修改更改?在具有事务的数据库中,所有修改操作(CREATE,INSERT等)都需要在事务中执行。

Have you tried performing your modifying change in a transaction? In databases with transactions all modifying operations (CREATE, INSERT, ...) need to be performed in a transaction.

ARdb.beginTransaction();
// your create code 
ARdb.commitTransaction();

这篇关于SQLite-没有错误,但是,没有数据上传到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆