This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes What are the problem ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "What are the problem ?" Watch "What are the problem ?" New topic
Author

What are the problem ?

Alex Marks
Ranch Hand

Joined: Sep 12, 2005
Posts: 31
I have the following code. Just a code to fill up the BLOB column in database.
--------------------------------------------------------------------
String template = "select picture from picture where id = ?";
Blob picture = null;
PreparedStatement statement = connection.prepareStatement(template);
statement.setString(1,values[0]);
ResultSet resultSet = statement.executeQuery();
while(resultSet.next())
{
picture = ((OracleResultSet)resultSet).getBlob(1);
}

File binaryFile = new File("fileName");
FileInputStream instream = new FileInputStream(binaryFile);
OutputStream outstream = picture.getBinaryOutputStream();

int size = picture.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;

while ((length = instream.read(buffer)) != -1)
outstream.write(buffer, 0, length);
instream.close();
outstream.close();
---------------------------------------------------------------------------
When I compile it, the compiler cannot find the method getBinaryOutputStream(); and getBufferSize(); What problem do I have ?
Thank you for you help and looking for your replies.


Before I come here, I am confused about Servlet/JSP. Ater I come here, I am more confused about it, but in systematically.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Neither of these methods are in the API for java.sql.Blob
It is possible you may be referring to an OracleBlob but your object type is Blob.

Personally I'm against casting to the specific Oracle types, but I hope it works for you
Alex Marks
Ranch Hand

Joined: Sep 12, 2005
Posts: 31
David O'Meara, Thank you for your help, I have solved wuch a problem. But I encounter another problem related to the above code.
java.sql.SQLException: ORA-01002: fetch out of sequence
what does this error mean ?
Thank you for your help !
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
There is something wrong in your first example where you want a Blob and cast to a specific ResultSet. You want to cast to an OracleBlob no?

Out of sequence errors... well it means you did something in a sequence (order) that the DB (or driver) didn't like. Often times I have seen it because you are trying to get the columns in a different order but I am not sure that is the problem here. Which line is causing the actual error?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What are the problem ?
 
Similar Threads
insert problem in oracle
opinion soughted
Reading From a Binary Large Object(BLOB)
Problem inserting Blob into Oracle DB
storing images in the database