Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POSTGRESQL: Batch entry 0 SELECT

Tags:

postgresql

Hi I have the following method which calls a stored function in postgresql. The call works when I use a standard executequery() method but does not work when I start using batchs. Any help will be appreciated.

public void addstuff3() throws Exception {
 Statement statement = null;
  ResultSet resultSet = null;
  Connection conn = null;
      try {
      // this will load the MySQL driver, each DB has its own driver
      Class.forName("org.postgresql.Driver");
      // setup the connection with the DB.
      conn = DriverManager
          .getConnection("jdbc:postgresql://localhost/newmydb?"
              + "user=new_user&password=password");

   // statements allow to issue SQL queries to the database
      statement = conn.createStatement();
      conn.setAutoCommit(false);
     statement.addBatch("SELECT ADDSTUFF('comp1',     'mdel1','power','PROPERTY','STRING','ON', '1396983600000', 'testing');");
     statement.addBatch("SELECT ADDSTUFF('comp2',     'mdel2','power','PROPERTY','STRING','ON', '1396983600000', 'testing');");
     conn.commit();
     statement.executeBatch();
    } catch (ClassNotFoundException | SQLException e) {
      throw e;
    } finally {
       conn.close();
    //   resultSet.close();
       statement.close();

    }

This is the Error I get:

Batch entry 0 SELECT ADDSTUFF('comp1', 'mdel1','power','PROPERTY','STRING','ON',     '1396983600000', 'testing') was aborted.  Call getNextException to see the cause.
at     org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Sta    tement.java:2743)
    at org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:461)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1928)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:405)
at     org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2892)
at jdbc.testing.MySQLAccess.addIndicators3(MySQLAccess.java:125)
at jdbc.testing.JDBCTesting.main(JDBCTesting.java:21)

Any help? I am using jdbc and postgresql.

like image 315
wwjdm Avatar asked Jul 22 '26 13:07

wwjdm


1 Answers

ok thanks to @Dave I found that

e.getNextException()
  1. Prints:

     A result was returned when none was expected
    
  2. I should not return a value

Works!

like image 82
wwjdm Avatar answered Jul 24 '26 04:07

wwjdm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!