Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

author
message
[Level:1]tanyona

Post subject: Executing multiple statements

registered: 04/30/2012

IP: *.49.88.105

views: 3

Is it possible to execute multiple statements using the Statement.execute() method, and access the statement results using the Statement.getMoreResults() method? e.g.

String sql="select * from table1 ; select * from table2;";

PreparedStatement ps = conn.prepareStatement(sql);

ps.execute();

Resultset rs = ps.getResultset();

while(ps.getMoreResults()){

rs=ps.getResultSet();

}

Quote
[Level:3]Esen Sagynov

# Post subject:Re: Executing multiple statements

profile

registered: 05/31/2011

IP: *.91.139.66

Hi tanyona,

Yes, it is possible. Your code is correct.

Quote
[Level:1]tanyona

# Post subject:Re: Executing multiple statements

profile

registered: 04/30/2012

IP: *.49.88.99

If I use the following code, it doesn't loop through all the recordsets ...

while(ps.getMoreResults(Statement.KEEP_CURRENT_RESULT)){
if (rs != null) {
rs.close();
}
rs=ps.getResultSet();
 
}

Quote
[Level:1]tanyona

# Post subject:Re: Executing multiple statements

profile

registered: 04/30/2012

IP: *.49.88.107

Would this be because the cubrid jdbc driver is a jdbc 2.0 driver and the getMoreResults overload I've used is a jdbc 3.0 method?

Quote
[Level:3]Esen Sagynov

# Post subject:Re: Executing multiple statements

profile

registered: 05/31/2011

IP: *.91.139.50

Yes, you're absolutely right! CUBRID JDBC complies with 2.0 spec which supports only one form of getMoreResults() method as shown below:

public boolean getMoreResults() throws SQLException {
...
}

As you can notice, in JDBC 2.0 spec getMoreResults() method doesn't accept any argument, while in JDBC 3.0 spec it accepts an integer.

When you try to pass an integer to CUBRID JDBC driver, it will not loop through all the resultsets because the method returns false meaning no more resultset are there. This is the default behavior for 2.0 compliant JDBC drivers.

public boolean getMoreResults(int current) throws SQLException {
    return false;
}

Quote
[Level:1]Timothy Anyona

# Post subject:Re: Executing multiple statements

profile

registered: 04/30/2012

IP: *.49.88.98

Thanks for the feedback Esen.

Quote




You are either using a very old browser or a browser that is not supported.
In order to browse cubrid.org you need to have one of the following browsers:



Internet Explorer: Mozilla Firefox: Google Chrome: