我想知道如何将 texfile 中的内容导入数据库 (javaDB)。这是我的代码,但是在执行时收到错误。我还想说明的是,该表的主键是自动递增的。
CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE
(null,'EXPENDITURE','C:\Users\Me\Desktop\textforimport.txt',null,null,null,0);
// This is my import code
//这是我的错误
Executed successfully in 0.003 s.
Line 1, column 1
Error code 30000, SQL state 38000: The exception 'java.sql.SQLException:
Attempt to modify an identity column 'EXPENDITURE_ID'.' was thrown while evaluating an expression.
Error code 99999, SQL state 42Z23: Attempt to modify an identity column 'EXPENDITURE_ID'.
Line 4, column 1
Execution finished after 0.003 s, 1 error(s) occurred.
//创建表的代码
create table Expenditure (
Expenditure_ID integer not null primary key generated always as identity (start with 1,increment by 1),
Expenditure_Description varchar (75) not null,
Expense double not null,
Expense_Date date not null
);
现在我不是java专家,但我想知道是否有人打电话来帮助我解决这个问题。我会很感激。谢谢
最佳答案
只需将您的 Expenditure_ID 声明更改为“GENERATED BY DEFAULT AS IDENTITY”,
An identity column that is GENERATED BY DEFAULT will only increment and use the default value on insertions when no explicit value is given. Unlike GENERATED ALWAYS columns, you can specify a particular value in an insertion statement to be used instead of the generated default value. source
关于java - 如何将文本文件导入到 java DB 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24682233/