Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

These are bugs of JDBC?

843859Mar 22 2008 — edited Mar 31 2008
Bug 1.

First, I created a database view like this:

CREATE VIEW test_v
AS
SELECT '' AS dummy, c1, c2, c3
FROM test_table
WHERE c4=1

Second, wrote java statements like below:

ResultSet rs = Statement.executeQuery("SELECT dummy, c1, c2 FROM test_v");
while(rs.next())
{
//I found call below was returned very slow
// But after I altered view code like ... NULL AS dummy..., the call was returned quickly!!!
String value = rs.getString(1);
}
// I found the problem above when I connected to SQL Server 2000 datebase using JdbcOdbc driver.


Another bug.

//sample code
Connection con = pool.getConnection();
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE
, ResultSet.CONCUR_READ_ONLY);
//The call below will throw a SQLException when the resultset has no any record.
stmt.executeQuery("SELECT a,MAX(b) FROM tableX WHERE c=10 GROUP BY a HAVING MAX(b)>2");

//The message of the exception is "Invalid cursor status"
//I reviewed the source code of JdbcObdcDriver, I found the programmer of this class had assumed
// that the resultset of select statement like "SELECT COUNT(*) FROM table ..." should always return 1 record.
// So he didn't wrote code like:
<code>
if (rs.next) rowCount = rs.getInt(1);
else rowCount = 0;
</code>
// but just
<code>
rowCount = rs.getInt(1);
</code>

But sometimes the resultset of statement like "SELECT {COUNT(*) | MAX(x) | MIN(x) | AVG(X)} FROM table GROUP BY y HAVING ..." maybe have not any record.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 28 2008
Added on Mar 22 2008
37 comments
710 views