This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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"
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
posted
0
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
posted
0
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
posted
0
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
posted
0
Hi, I am also trying similar thing Blob b =rs.getBlob("JOB");
>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.
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.