[英]Jooq insert statement without code generation
I am using jOOQ to generate SQL statements. 我正在使用jOOQ生成SQL语句。 How can I create an insert statement?
如何创建插入语句? I am able to generate a select statement, but I am unable to generate an insert statement.
我能够生成一个select语句,但我无法生成一个insert语句。 I can create a select statement like this:
我可以像这样创建一个select语句:
String selectSQL = create.select().from("author").getSQL();
How can I create the SQL statement for insert 如何为insert插件创建SQL语句
try {
Class.forName("com.mysql.cj.jdbc.Driver");
dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/library?autoReconnect=true&useSSL=false","root","abcd");
DSLContext create = DSL.using(dbConnection,SQLDialect.MYSQL);
String SQl = create.insertInto(Table<?> table("author"), Field<Object> field("id"),Field<Object> field("first_name").Field<Object> field("last_name")).values("1", "askdfj", "kdjvk").getSQL();
}
You need to use: 你需要使用:
create
.insertInto(table("author"), field("id"), field("first_name"), field("last_name"))
.values("1", "askdfj", "kdjvk")
Where table
and field
are a static import of org.jooq.impl.DSL.table
and org.jooq.impl.DSL.field
. table
和field
是org.jooq.impl.DSL.table
和org.jooq.impl.DSL.field
的静态导入。
Note that your code had several syntax errors (eg Table<?>
and Field<Object>
where they don't belong, and a .
instead of a ,
). 请注意,您的代码有几个语法错误(如
Table<?>
和Field<Object>
他们不属于,并且.
而不是一个,
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.