【问题标题】:Is it possible to get full request from preparedStatement? [duplicate]是否可以从preparedStatement 获得完整的请求? [复制]
【发布时间】:2020-05-22 05:42:32
【问题描述】:

我已经连接到数据库

    props.setProperty("user", login);
    props.setProperty("password", password);
    props.setProperty("reWriteBatchedInserts", "true");

PreparedStatement

        ps = connection.prepareStatement(sqlStr);
        //...
        psRegion.addBatch();

我怎样才能从 statemrnt 获得完整的请求?如果我尝试System.out.println(ps);,我只能使用最后添加的参数进行查询。

我需要得到insert into a.a(x,y) values (x1,y1), (x2,y2), ...;

【问题讨论】:

  • 重写可能发生在驱动程序代码的更深处,为什么你认为你需要得到它?如果您只想记录日志,则应该使用 println() 的其他内容。
  • 这能回答你的问题吗? Get query from java.sql.PreparedStatement

标签: java postgresql


【解决方案1】:

Amongalen 的评论将您指向一般答案,但在 PostgreSQL 中,您有时可以通过查询pg_prepared_statements 系统目录找到答案。

我说“有时”,因为默认情况下,JDBC 驱动程序不会立即创建服务器端准备好的语句,只有当该语句执行超过 5 次时。

详情请参阅JDBC driver documentation

【讨论】:

    猜你喜欢
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 2018-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多