【问题标题】:How to Alter table using JOOQ?如何使用 JOOQ 更改表?
【发布时间】:2013-10-24 10:14:21
【问题描述】:

以前我正在使用语句,但我需要使用 JOOQ 转换它

  Statement dboSt = null; 

dboSt = dboConn.createStatement(); 

我需要知道如何在 JOOQ 中更改以下行。

dboSt.executeUpdate("alter login \"" + UserId + "\" with password='" + NewPassword + "'");

dboSt.executeUpdate("alter login \"" + UserId + "\" with password='" + NewPassword + "' old_password='" + OldPassword
                                + "'");

有什么办法可以转换吗?

【问题讨论】:

    标签: java sql jooq


    【解决方案1】:

    jOOQ 还不支持类型安全的 DDL。它已经在路线图上一段时间了:#883

    同时,您可以直接使用 jOOQ 执行纯 SQL 语句,例如:

    DSLContext ctx = DSL.using(configuration);
    
    // As before, manually inlining arguments:
    ctx.execute("alter login \""+UserId+"\" with password='"+NewPassword+"'");
    
    // Better, letting jOOQ do the string escaping for you, preventing
    // syntax errors and SQL injection vulnerabilities:
    ctx.execute("alter login {0} with password = {1}",
        DSL.name(UserId),       // org.jooq.Name is rendered with quotes in most DBs
        DSL.inline(NewPassword) // org.jooq.Param is inlined as a (string) literal
    );
    

    【讨论】:

    • 如何转换以下代码:dboSt.executeUpdate("alter login \"" + UserId + "\" with password='" + NewPassword + "' old_password='" + OldPassword + "'" );
    • @psisodia:得到这个答案只是我现有答案的一小步。你可以自己做一些思考:-)
    猜你喜欢
    • 2018-05-25
    • 2020-11-02
    • 1970-01-01
    • 2012-01-06
    • 2020-10-21
    • 2017-06-29
    • 2012-08-05
    • 2017-12-13
    • 2020-06-06
    相关资源
    最近更新 更多