0

I have connection to database

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

PreparedStatement

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

How can i get full request from statemrnt? If i try System.out.println(ps); i have query only with last added parameters.

I need to get insert into a.a(x,y) values (x1,y1), (x2,y2), ...;

Krazim00da
  • 307
  • 1
  • 5
  • 14
  • The rewriting probably happens deeper down in the driver code, why do you think you need to get it? If you just want logging, that should be done with something else that `println()`. – Kayaman Feb 06 '20 at 08:28
  • 2
    Does this answer your question? [Get query from java.sql.PreparedStatement](https://stackoverflow.com/questions/2683214/get-query-from-java-sql-preparedstatement) – Amongalen Feb 06 '20 at 08:29

1 Answers1

0

Amongalen's comment points you to general answers, but in PostgreSQL you sometimes can find the answer by querying the pg_prepared_statements system catalog.

I say "sometimes", because by default the JDBC driver will not immediately create a server side prepared statement, only if the statement is executed more than 5 times.

See the JDBC driver documentation for details.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263