• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

opinion soughted

 
honey singh
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
honey singh
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Luqman Qaiser
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the JDBC forum.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    Stefan Evans
    Bartender
    Posts: 1807
    10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    >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
    Posts: 13459
    Android Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic