There is a workaround. I fetched the column index before while(rs.next()) . The below snippet works absolutely fine for me.
But I still fail to understand why resultSet. GetString(columnName) failed inside while(rs.next()) .
Up vote 0 down vote favorite share g+ share fb share tw.
I have a oracle(10.2) PLSQL procedure which fetches 15 records from a table in a sysrefcursor. I then pass this cursor to a java class as a resultset. This java class is loaded to oracle.
Driver name : Oracle JDBC driver Driver Version : 10.2.0.1.0 Driver Major Version : 10 Driver Minor Version : 2 Observations: 1 Inside the java class, when I iterate through the resultset I get only the first 10 records. 2 If the cursor fetched (20 or more records) or (10 or less) I could get all the records while iterating the resultset. 3 I found that the default fetchsize for the resultset is 10.
If I change the fetchSize to 5, and the cursor fetches 8 records, I could get the first 5 records while iterating the resultset. 4 If the cursor fetched (10 or more records) or (5 or less) I could get all the records while iterating the resultset. 5 If I change the resultset fetchSize to 1, I could get all the records in the resultset no matter how many records are fetched by the cursor.
Why is the resultset behaving weirdly? Public static BLOB createZip(BLOB prevBlob, String outPrefix, ResultSet entries, ResultSet rs, Long resultRows) throws Exception { OracleConnection conn = null; BLOB retBLOB = null; int page = 1; int curRow = 0; long totalRows = 0; try { conn = (OracleConnection) new OracleDriver(). DefaultConnection(); ArrayList entryList = loadEntries(entries); retBLOB = BLOB.
CreateTemporary(conn, true, BLOB. DURATION_SESSION); retBLOB. Open(BLOB.
MODE_READWRITE); OutputStream bOut = retBLOB. SetBinaryStream(0L); ZipOutputStream zipOut = new ZipOutputStream(bOut); PrintStream out = new PrintStream(zipOut); zipOut. PutNextEntry(new ZipEntry(outPrefix + "-p" + page + ".
Csv")); writeHeader(out, entryList); while (rs.next()) { curRow++; totalRows++; if (curRow >= maxPageSize) { zipOut.closeEntry(); page++; zipOut. PutNextEntry(new ZipEntry(outPrefix + "-p" + page + ". Csv")); writeHeader(out, entryList); curRow = 0; } for (int I = 0; I 0) { out.
Write(buf, 0, len); } inEntry = zipIn.getNextEntry(); } zipIn.close(); try { prevBlob.freeTemporary(); } catch (SQLException e) { } } zipOut.close(); retBLOB.close(); return retBLOB; } catch (Exception sex) { if (retBLOB! = null) { try { retBLOB.freeTemporary(); } catch (SQLException e) { } } throw sex; } finally { try { entries.close(); } catch (SQLException sex) { } try { rs.close(); } catch (SQLException sex) { } try { if (conn! = null ||!conn.isClosed()) { conn.close(); } } catch (SQLException ex) { ex.printStackTrace(); } } } java oracle jdbc link|improve this question edited Oct 6 '10 at 10:29 asked Oct 6 '10 at 9:44Surjit8018 29% accept rate.
Statistically it is a lot more likely that you have a bug in your code and that the ResultSet is behaving as intended. Can you share a sample of your code? – Vincent Malgrat Oct 6 '10 at 9:59 I have shared the code.
It doesn't look like I m doing something wrong. – Surjit Oct 6 '10 at 10:39 2 Looks complex, but okay... Does this also happen when you remove all other code (opening another connection, creating a blob, reading from the second result set) except the loop over rs (and maybe rs. GetString in the loop)?
– Thilo Oct 6 '10 at 12:35 You were right. Thanks. It behaved normally without the 'other codes'.
Let me debug more into it. – Surjit Oct 6 '10 at 13:02 If I have rs. GetString(e.getColumn()) in my code, then the issue crops up.
Otherwise its fine. – Surjit Oct 6 '10 at 13:41.
There is a workaround. I fetched the column index before while(rs.next()). The below snippet works absolutely fine for me.
But I still fail to understand why resultSet. GetString(columnName); failed inside while(rs.next()). ArrayList entryList = loadEntries(entries); int colIndx = new intentryList.size(); ResultSetMetaData rsmd = rs.getMetaData(); int numberOfColumns = rsmd.getColumnCount(); for (int I = 0; I Get(i); for (int j = 1; j Length ; i++){ System.out.
Println("Column Values"+colIndxi+" : "+rs. GetString(colIndxi)); } } }.
It seems strange indeed. You may have found a bug. By any chance does the cursor have two columns with the same name?
– Vincent Malgrat Oct 7 '10 at 8:03 No, all the column names are unique. – Surjit Oct 7 '10 at 8:27 If it were easy to do that, I'd say file a bug with Oracle. – Thilo Oct 9 '10 at 1:49.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.