Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

author
message
[Level:1]tanyona

Post subject: PreparedStatement getUpdateCount issue

registered: 05/01/2012

IP: *.49.88.107

views: 1

I have the following code.

String sql="update table1 set col1=1; select * from table2; select * from table3";
 
PreparedStatement ps = conn.prepareStatement(sql);
 
ps.execute();
 
Resultset rs = ps.getResultset();
int updateCount = ps.getUpdateCount();

while(ps.getMoreResults() || ps.getUpdateCount() != -1){ 
	rs = ps.getResultSet();
	updateCount = ps.getUpdateCount();
}

It seems like the getUpdateCount method doesn't return an updated value if a select statement follows an update statement. I would expect the updateCount variable to have -1 at the end of the loop but instead it has the result from the update statement.

Quote
[Level:3]Esen Sagynov

# Post subject:Re: PreparedStatement getUpdateCount issue

profile

registered: 05/31/2011

IP: *.91.139.66

Hi tanyona,

You're right about this issue. I've just reported it to our JDBC Dev Team (http://bts4.nhncorp.com/nhnbts/browse/CUBRIDSUS-10253 - internal link). I'll get back to you with details about whether this is a bug or an expected behavior according to the spec.

For now as a workaround you can simply add a test condition to check whether the restulset is not null, like:

while(ps.getMoreResults() || ps.getUpdateCount() != -1){ 
    rs = ps.getResultSet();
    // updateCount will report an incorrect value, saying "1" for all resultsets after "Update" statement.
    updateCount = ps.getUpdateCount();
    // so check if resultset is not null. If it is null, then it's an "update" statement and updateCount is correct.
    // if resultset is not null, then ignore updateCount.
    if (rs != null) {
        // do something with it
    }
}

Let me know if you have other questions.

Quote
[Level:1]Timothy Anyona

# Post subject:Re: PreparedStatement getUpdateCount issue

profile

registered: 05/01/2012

IP: *.49.88.98

Hi Esen,

Thanks for the feedback. No other questions for now. I was testing some functionality with a couple of databases and CUBRID was behaving a bit differently. I ended up using the logic you've indicated.

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: