statement « postgresql « Java Database Q&A

1. How do I get at the sql statement that caused an SQLException using the Postgres JDBC driver in Java?


In my current project - a server product with no GUI front-end, I'm trying to write in better error handling support. Errors currently are outputted to the logs and are typically ...

2. JDBC postgres statement_timeout

Suppose I have:

untimedStatement = connection.createStatement() ;
timedStatement = connection.createStatement();
And then run
timedStatement.execute("SET statement_timeout TO " + timeout);
Will the SET statement_timeout command also affect untimedStatement? I was hoping it would not but some ...

3. Parameterized Query: Check if field is in array of values in SELECT statement

I'm trying to configure a parameterized query to the effect of:

SELECT field1 FROM myTable WHERE field2 IN (1,2,3,4)
The database I'm using is Postgres. This query run successfully unparameterized, but I'd like to ...

4. How do I compress both this postgresql query into one statement in java?

package database;

    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import database.Dbconnect;

    public ...

5. Logging prepared sql statements in postgres jdbc driver

I want to log all prepared sql statements in my java application. I'm using the standard postgres jdbc driver org.postgresql.Driver. This driver has a parameter called " loglevel" which can be ...