[英]Unable to insert values in SQLite3 database using JDBC
I have the following JDBC code , in which I am not getting any error, but unfortunately the data is not being added to the database. 我有以下JDBC代码,但没有收到任何错误,但是很遗憾,没有将数据添加到数据库中。 The code that I am using is : 我正在使用的代码是:
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:../../clientDb.db");
c.setAutoCommit(false);
String expenseUUID = UUID.randomUUID().toString();
expenseUUID = expenseUUID.replaceAll("-", "");
String sqlQuery = "insert into expense (expenseUUID , user_id,expense_description,
total_amount, place, per_exp_flag, category " +
",creation_date ) values (?,?,?,?,?,?,?,?) ";
ps = c.prepareStatement(sqlQuery);
ps.setString(1, expenseUUID);
ps.setInt(2, user_id);
ps.setString(3, description);
ps.setInt(4, total_amount);
ps.setString(5, place);
ps.setInt(6, 1);
ps.setInt(7, category);
ps.setString(8, creation_date);
int result = ps.executeUpdate();
if(result == 1){
b = true;
}
What is the error ? 有什么错误? When I tried using select statement , I got the result in the result set, But why is it not inserting anything? 当我尝试使用select语句时,我在结果集中得到了结果,但是为什么不插入任何内容呢? I am getting '1' in 我得到'1'
int result = ps.executeUpdate();
What is possibly the error? 可能是什么错误? I am using SQLite3 as back-end database. 我正在使用SQLite3作为后端数据库。
You have c.setAutoCommit(false);
你有c.setAutoCommit(false);
so your INSERT won't actually be written to the database until you c.commit();
因此,直到c.commit();
您的INSERT才会真正写入数据库c.commit();
. 。 Add that statement after the ps.executeUpdate()
. 在ps.executeUpdate()
之后添加该语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.