2

I know how to run a simple "select * from table" in java postgres jdbc connector.

But how do we run two or more statements, where statement2 depends on statement1 using java/JDBC-Postgres?

Example #1:
SET search_path TO a,b,c;
Select * from table1;

Example #2:
Create temporary table tempabc ... definition and value;
Select * from tableDEF inner join tempabc USING (tableDEF.refid = tableDEF.id) where table a=1;

This question may already be answered but I cannot find duplicates for it. If nothing in staightforward JDBC-Postgres way let me know other ways. Thanks!

RonPringadi
  • 1,294
  • 1
  • 19
  • 44

2 Answers2

4

This may be what you are looking for: Batch statements. The caveat is that your statements must be insert/update/delete (actions).

http://www.mkyong.com/jdbc/jdbc-preparedstatement-example-batch-update/

JavaDoc for addBatch

Alternatively, you could execute a stored proc and return cursors. More on that here: https://stackoverflow.com/a/10804730/559095

Community
  • 1
  • 1
Sid
  • 7,511
  • 2
  • 28
  • 41
3

for the first question you can use setSchema to change the search path As for the second as long as you use the same connection the temporary table will be there.

Dave Cramer
  • 76
  • 1
  • 4