These are bugs of JDBC?
843859Mar 22 2008 — edited Mar 31 2008Bug 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.