Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes fetch out of sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "fetch out of sequence" Watch "fetch out of sequence" New topic
Author

fetch out of sequence

Tia Wai
Greenhorn

Joined: Sep 19, 2001
Posts: 1
Hi,
I'm trying simple loading of an image file into Oracle as a Blob, but keep getting the error:ORA-01002: fetch out of sequence.
The code is as follows:
BLOB blob = null;
stmt.execute("CREATE TABLE img (name varchar(10), data blob)");
stmt.execute("INSERT INTO img VALUES ('test', empty_blob())");
stmt.execute("commit");
String cmd = "SELECT * FROM img WHERE name='test' FOR UPDATE";
ResultSet rset = stmt.executeQuery(cmd);
while(rset.next())
blob = ((OracleResultSet)rset).getBLOB(2);
What am I doing wrong?? Please help!
Thanks.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

taken from the oracle docs:
Error Message: "ORA-01002: fetch out of sequence"
A JDBC Connection by default has the AutoCommit turned ON. However, to use a SQL that has 'for update' you need to have autoCommit to be turned OFF.
Hence, the solution is to set autocommit to false.
http://otn.oracle.com/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#_18_
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: fetch out of sequence