[英]Java code to insert data into a table by retrieving the result from another query
I have sql query which works well if I have to run it manually in sql command line or IDE.我有 sql 查询,如果我必须在 sql 命令行或 IDE 中手动运行它,它运行良好。 But I have to convert that into java code and the query is not working in java.
但是我必须将其转换为 java 代码,并且查询在 java 中不起作用。 Sql query -
Sql查询-
"INSERT INTO table_1(column1, column2,column3, column4, column5)
SELECT DISTINCT s.computedmetric_name AS metric_name, s.display_name, FALSE
AS is_generated,FALSE AS is_manually_marked_for_deletion, FALSE AS
is_data_marked_for_deletion FROM db_computedmetrics_temp AS s WHERE
s.computedmetric_name IS NOT NULL AND s.display_name IS NOT NULL AND NOT
EXISTS (SELECT 1 FROM db_metrics AS t WHERE t.metric_name =
s.computedmetric_name)"
I am trying with below java code我正在尝试使用以下 java 代码
String sql="Above mentioned sql query directly into this string";
Statement stmt = sqliteDBConnection.createStatement();
stmt.executeUpdate(sql);
But while running the code I am getting the exception saying that -但是在运行代码时,我收到异常说 -
Exception in thread "main" org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such column: FALSE)
Please note the earlier sql was written for postgres DB and Java code is connecting to sqllite db.请注意,较早的 sql 是为 postgres DB 编写的,而 Java 代码正在连接到 sqllite db。 Please help me out to convert the sql to work with java.
请帮助我将 sql 转换为与 java 一起使用。 Thank you!
谢谢!
SQLite doesn't support TRUE
and FALSE
as keywords SQLite 不支持
TRUE
和FALSE
作为关键字
SQLite does not have a separate Boolean storage class.
SQLite 没有单独的布尔存储类。 Instead, Boolean values are stored as integers 0 (false) and 1 (true).
相反,布尔值存储为整数 0 (false) 和 1 (true)。
http://www.sqlite.org/datatype3.html http://www.sqlite.org/datatype3.html
So you have to change your query to something like this所以你必须将你的查询更改为这样的
INSERT INTO table_1(column1, column2,column3, column4, column5)
SELECT DISTINCT s.computedmetric_name AS metric_name, s.display_name, 0
AS is_generated,0 AS is_manually_marked_for_deletion, 0 AS
is_data_marked_for_deletion FROM db_computedmetrics_temp AS s WHERE
s.computedmetric_name IS NOT NULL AND s.display_name IS NOT NULL AND NOT
EXISTS (SELECT 1 FROM db_metrics AS t WHERE t.metric_name =
s.computedmetric_name)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.