简体   繁体   English

Jooq插入语句没有代码生成

[英]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 . tablefieldorg.jooq.impl.DSL.tableorg.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>他们不属于,并且.而不是一个, )。

On the official doc you have an example 在官方文档上你有一个例子

create.insertInto(AUTHOR,
    AUTHOR.ID, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
  .values(100, "Hermann", "Hesse");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM