aspose file tools*
The moose likes JDBC and the fly likes opinion soughted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "opinion soughted" Watch "opinion soughted" New topic
Author

opinion soughted

honey singh
Ranch Hand

Joined: Apr 26, 2002
Posts: 44
I'm making web application usin JSP....now I want to update data in the blob field which I'm doing like this

cmd="select * from transaction where trans_no='"transacId+"'";
rs=stmt.executeQuery(cmd);
file=new java.io.File(filePathName);
long f_size=file.length();
buffer=new byte[(int)f_size];
instream=new FileInputStream(file);
length=-1;
while((length=instream.read(buffer))!=-1)
{
}
rs.updateBytes("f_file",buffer);
rs.updateRow();

where f_file is the blob field....

Is this way ok? actually when I try the same thing with class and compile it using jdk then it gives the following excwption:
"java.lang.UnsupportedOperationException"

so this means there will be same error in JSP?

If this is not ok please suggest me some other way of doin this..

thanx in advance!
[ August 22, 2005: Message edited by: Bear Bibeault ]
chanoch wiggers
Author
Ranch Hand

Joined: May 24, 2001
Posts: 245
are you sure you have access to JDBC 2.0? You should run checks on the META data object for you connection to checking that you can use updateRow() and so on. my guess is that if you check you will find its not updateable or your driver is not JDBC2


chanoch<p><a href="http://www.amazon.com/exec/obidos/ASIN/1861007736/" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
honey singh
Ranch Hand

Joined: Apr 26, 2002
Posts: 44
I'm modifying my question
I may say like this that what method should I follow to upload data in to the BLOB field?
firstly I use this method
1)
stmt.execute ("INSERT INTO my_blob_table VALUES ('row1', empty_blob())");
BLOB blob;
cmd = "SELECT * FROM my_blob_table WHERE X='row1'";
ResultSet rest = stmt.executeQuery(cmd);
BLOB blob = ((OracleResultSet)rset).getBLOB(2);
File binaryFile = new File("john.gif");
FileInputStream instream = new FileInputStream(binaryFile);
OutputStream outstream = blob.getBinaryOutputStream();
int size = blob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;
while ((length = instream.read(buffer)) != -1)
outstream.write(buffer, 0, length);
instream.close();
outstream.close();
for this I had to import oracle.jdbc.OracleResultSet class and oracle.sql.BLOB class from classes12.jar...but when I compile it I get the following error
for **********BLOB blob = ((OracleResultSet)rset).getBLOB(2);********
which is "interfaces java.sql.ResultSet and oracle.jdbc.OracleResultSet are incompatible; bot define getArray(java.lang.String), but with different return type""

And the second method is
2)
stmt.execute ("INSERT INTO my_blob_table VALUES ('row1', empty_blob())");
cmd = "SELECT * FROM my_blob_table WHERE X='row1'";
File binaryFile = new File("john.gif");
FileInputStream instream = new FileInputStream(binaryFile);
OutputStream out=blob.setBinaryStream(pos);
int length=-1;
long pos=0;
long f_size=file.length();
byte buffer[]=new byte[(int)f_size];
Blob blob=rs.getBlob("f_file");
while((length=instream.read(buffer))!=-1)
{
out.write(buffer,0,length);
}
rs.updateBytes("f_file",buffer);
rs.updateRow();
and close all bla bla
and it gives the exception "java.lang.UnsupportedOperationException"..
coz this feature is available in j2sdk1.4
but when I use j2sdk1.4 then I'm not able to connect to database...
please if u can suggest any way out for this..
If there is another method of populating the data in the Blob field of the database plz suggest me...
thanx.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
harmanjeet s
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


Dave
Luqman Qaiser
Greenhorn

Joined: Aug 21, 2005
Posts: 18
Hi,
I am also trying similar thing
Blob b =rs.getBlob("JOB");

But am getting this exception
java.lang.UnsupportedOperationException
at sun.jdbc.odbc.JdbcOdbcResultSet.getBlob(Unknown Source)

I am using the following driver
sun.jdbc.odbc.JdbcOdbcDriver

Kindly suggest the solution.

regards,
Lucky
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61752
    
  67

Moved to the JDBC forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by harmanjeet s:
and it gives the exception "java.lang.UnsupportedOperationException"..
coz this feature is available in j2sdk1.4

but when I use j2sdk1.4 then I'm not able to connect to database...
please if u can suggest any way out for this..


Can you:
  • Tell us which driver you think you are using.
  • Show us the code you use to get your connection object

  • And perhaps we can help.


    JavaRanch FAQ HowToAskQuestionsOnJavaRanch
    Stefan Evans
    Bartender

    Joined: Jul 06, 2005
    Posts: 1026
    >java.lang.UnsupportedOperationException
    >at sun.jdbc.odbc.JdbcOdbcResultSet.getBlob(Unknown Source)

    >I am using the following driver: sun.jdbc.odbc.JdbcOdbcDriver

    >Kindly suggest the solution.
    Don't use the JdbcOdbc driver.
    Get a proper JDBC driver for your database.
    All the common databases (Oracle, MS SQL, MySQL) have pure java jdbc drivers.
    David O'Meara
    Rancher

    Joined: Mar 06, 2001
    Posts: 13459

    for this I had to import oracle.jdbc.OracleResultSet class and oracle.sql.BLOB class from classes12.jar...but when I compile it I get the following error
    for **********BLOB blob = ((OracleResultSet)rset).getBLOB(2);********
    which is "interfaces java.sql.ResultSet and oracle.jdbc.OracleResultSet are incompatible; bot define getArray(java.lang.String), but with different return type""


    Don't cast to the Oracle specific types, always try to stick with the generic JDBC classes. As the previous posts says, try to use the Oracle thin driver.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: opinion soughted