Blob objects
We are using Oracle 8i with the jdbc driver. We have trouble with storing a blob in the database when it is larger than the chunksize using the jdbc interface for PreparedStatement.set
Code that stores only smaller blobs :
InputStream bais = new ByteArrayInputStream(value);
PreparedStatement pstmt = con.prepareStatement("INSERT INTO " + tableName + " VALUE (? ) " );
pstmt.setBinaryStream(1, bais, value.length );
pstmt.executeUpdate();
Code that works:
oracle.sql.BLOB myBlob = ((OracleResultSet) rs).getBLOB( columnName);
OutputStream outStream = myBlob.getBinaryOutputStream(); outStream.write(value, 0, value.length);outStream.flush();
outStream.close();
null
I don't know the answer, sorry. This is the jdb (java debugger) tool forum.
You might want to post your question over on the JDBC forum.
http://forum.java.sun.com/forum.jsp?forum=48
Similar Messages
-
Can not retrieve cell data content From BLOB object.
I have load Image into Georaster with Raster_Table following:
create table rdt_1 of mdsys.sdo_raster
(primary key (rasterId, pyramidLevel, bandBlockNumber,
rowBlockNumber, columnBlockNumber))
lob(rasterblock) store as (nocache nologging);
After I load Image successful, I continue load all cell data into BLOB object by:
DECLARE
gr sdo_georaster;
lb blob;
BEGIN
SELECT georaster INTO gr FROM georaster_table WHERE georid=2;
dbms_lob.createTemporary(lb, FALSE);
sdo_geor.getRasterData(gr, 0, lb);
dbms_lob.freeTemporary(lb);
END;
Please give me simple PL/SQL to retrieval content from BLOB object!
Thank You very much!
YuMiBLOB stands for Binary Large OBject. However the acronym has a pleasing affinity with the actual nature of the thing. In a database a BLOB is an undiffereniated mass of bytes. We don't know whether it's a spreadsheet or a word document or an image. So there is no out-of-the-box API for treating a BLOB as it's native file type.
Having said that there may be something in the Spatial API that works with such things - you might be better off asking the question in Spatial. Although I suspect that venue doesn't get as much through traffic as this one.
Cheers, APC -
How to upload a image or flash file as blob object in a table.
How to upload a image or flash file as blob object in a table.
What are all the possible ways we can do it.Searching the forum (or google) would be my first choice, as this question pops up every now and then.
Next without knowledge of your environment (jdev version and technology stack) it's hard to give a profound answer.
All I can say is that it's possible.
Timo -
Parsing a UTF-8 encoded XML Blob object
Hi,
I am having a really strange problem, I am fetching a database BLOB object containing the XMLs and then parsing the XMLs. The XMLs are having some UTF-8 Encoded characters and when I am reading the XML from the BLOB, these characters lose their encoding, I had tried doing several things, but there is no means I am able to retain their UTF encoding. The characters causing real problem are mainly double qoutes, inverted commas, and apostrophe. I am attaching the piece of code below and you can see certain things I had ended up doing. What else can I try, I am using JAXP parser but I dont think that changing the parser may help because, here I am storing the XML file as I get from the database and on the very first stage it gets corrupted and I have to retain the UTF encoding. I tried to get the encoding info from the xml and it tells me cp1252 encoding, where did this come into picture and I couldn't try it retaining back to UTF -8
Here in the temp.xml itself gets corrupted. I had spend some 3 days on this issue. Help needed!!!
ResultSet rs = null;
Statement stmt = null;
Connection connection = null;
InputStream inputStream = null;
long cifElementId = -1;
//Blob xmlData = null;
BLOB xmlData=null;
String xmlText = null;
RubricBean rubricBean = null;
ArrayList arrayBean = new ArrayList();
rs = stmt.executeQuery(strQuery);
// Iterate till result set has data
while (rs.next()) {
rubricBean = new RubricBean();
cifElementId = rs.getLong("CIF_ELEMENT_ID");
// get xml data which is in Blob format
xmlData = (oracle.sql.BLOB)rs.getBlob("XML");
// Read Input stream from blob data
inputStream =(InputStream)xmlData.getBinaryStream();
// Reading the inputstream of data into an array of bytes.
byte[] bytes = new byte[(int)xmlData.length()];
inputStream.read(bytes);
// Get the String object from byte array
xmlText = new String(bytes);
// xmlText=new String(szTemp.getBytes("UTF-8"));
//xmlText = convertToUTF(xmlText);
File file = new File("C:\\temp.xml");
file.createNewFile();
// Write to temp file
java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter(file));
out.write(xmlText);
out.close();What the code you posted is doing:
// Read Input stream from blob data
inputStream =(InputStream)xmlData.getBinaryStream();Here you have a stream containing binary octets which encode some text in UTF-8.
// Reading the inputstream of data into an
into an array of bytes.
byte[] bytes = new byte[(int)xmlData.length()];
inputStream.read(bytes);Here you are reading between zero and xmlData.length() octets into a byte array. read(bytes[]) returns the number of bytes read, which may be less than the size of the array, and you don't check it.
xmlText = new String(bytes);Here you are creating a string with the data in the byte array, using the platform's default character encoding.
Since you mention cp1252, I'm guessing your platform is windows
// xmlText=new new String(szTemp.getBytes("UTF-8"));I don't know what szTemp is, but xmlText = new String(bytes, "UTF-8"); would create a string from the UTF-8 encoded characters; but you don't need to create a string here anyway.
//xmlText = convertToUTF(xmlText);
File file = new File("C:\\temp.xml");
file.createNewFile();
// Write to temp file
java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter(file));This creates a Writer to write to the file using the platform's default character encoding, ie cp1252.
out.write(xmlText);This writes the string to out using cp1252.
So you have created a string treating UTF-8 as cp1252, then written that string to a file as cp1252, which is to be read as UTF-8. So it gets mis-decoded twice.
As the data is already UTF-8 encoded, and you want the output, just write the binary data to the output file without trying to convert it to a string and then back again:// not tested, as I don't have your Oracle classes
final InputStream inputStream = new BufferedInputStream((InputStream)xmlData.getBinaryStream());
final int length = xmlData.length();
final int BUFFER_SIZE = 1024; // these two can be
final byte[] buffer = new byte[BUFFER_SIZE]; // allocated outside the method
final OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
for (int count = 0; count < length; ) {
final int bytesRead = inputStream.read(buffer, 0, Math.min(BUFFER_SIZE, (length - count));
out.write(buffer, 0, bytesRead);
count += bytesRead;
}Pete -
how to retrieve a blob object from oracle and display it??
kindly help :)subbu wrote:
how to retrieve a blob object from oracle and display it??1. Define what 'blob' contains.
2. Define what 'display' means in the context of 1 and other goals.
3. Write code to retrieve the object using the appropriate jdbc code from the appropriate database.
4. Test the code in 3.
5. Write code that implements 2.
6. Test the code of 5.
7. Add the code in 3 into the code of 5. -
Getting ClassCastException when accessing Blob object
I am using weblogic 5.1 with service pack 10.
I need to query pdf data stored in a blob field in Oracle
8.1.6 server. The native code c:\weblogic\bin\oci816_8
is part of the path. When I query the database with
Oracle 8 client, I can get data.
driver: weblogic.jdbc20.oci.Driver
url: jdbc20:weblogic:oracle:mydb
What I have done is to get the blob object with:
Blob blob = rs.getBlob(5);
long len = blob.length();
But when I call the blob.length();
I got the a ClassCastException. I really appreicate
your comment.
The exception message is:
====================================================
java.lang.ClassCastException: java.lang.String
at weblogic.jdbc20.oci.Blob.length(Blob.java:75)
at com.agf.profile.ProfileServlet.doProcess(ProfileServlet.java:126)
at com.agf.profile.ProfileServlet.doGet(ProfileServlet.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletSt
pl.java:120)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(Servle
textImpl.java:922)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(Servle
textImpl.java:886)
at weblogic.servlet.internal.ServletContextManager.invokeServlet(Ser
ContextManager.java:269)
at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP
a:380)
at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)
====================================================
Thanks,
Jianhi jian,
it seems you are trying to access a column as a blob type when the data in
that column is not blob.
Make sure that your column number 5 is defined as Blob in the database.
I tried the following code and it worked fine for me.
Blob b=rs.getBlob("data");
long l=b.length();
byte bt[]=b.getBytes(1,(int)b.length());
File f=new
File("d:\\bea\\wlserver6.1\\config\\jdbcdomain\\applications\\defaultwebapp\
\blob_new.pdf");
FileOutputStream fos=new FileOutputStream(f);
fos.write(bt);
fos.close();
It was able to create the file blob_new.pdf
But when I tried the following code it gave me the same exception as you are
getting
Blob bb=rs.getBlob("id");
long ll=bb.length();
Where id is a column in the database of varchar type
I am using the following settings
driver: weblogic.jdbc.oci.Driver
url: jdbc:weblogic:oracle
i am using wl 6.1 and oracle 8
Hope this helps you.
johnny
"jian zhang" <[email protected]> wrote in message
news:[email protected]...
>
I am using weblogic 5.1 with service pack 10.
I need to query pdf data stored in a blob field in Oracle
8.1.6 server. The native code c:\weblogic\bin\oci816_8
is part of the path. When I query the database with
Oracle 8 client, I can get data.
driver: weblogic.jdbc20.oci.Driver
url: jdbc20:weblogic:oracle:mydb
What I have done is to get the blob object with:
Blob blob = rs.getBlob(5);
long len = blob.length();
But when I call the blob.length();
I got the a ClassCastException. I really appreicate
your comment.
The exception message is:
====================================================
java.lang.ClassCastException: java.lang.String
at weblogic.jdbc20.oci.Blob.length(Blob.java:75)
atcom.agf.profile.ProfileServlet.doProcess(ProfileServlet.java:126)
at com.agf.profile.ProfileServlet.doGet(ProfileServlet.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
atweblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletSt
pl.java:120)
atweblogic.servlet.internal.ServletContextImpl.invokeServlet(Servle
textImpl.java:922)
atweblogic.servlet.internal.ServletContextImpl.invokeServlet(Servle
textImpl.java:886)
atweblogic.servlet.internal.ServletContextManager.invokeServlet(Ser
ContextManager.java:269)
atweblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP
a:380)
atweblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:
>
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)
====================================================
Thanks,
Jian -
Through a UI uploaded attachments are getting stored in DB as blob objects
Now we need to Ftp these attachments to our service providers particular location
Could someone tell me how to go about it
Should i be using DBadapter to select the blob object and then ftp it
What is the correct way ?
Thanks,
AkashShould i be using DBadapter to select the blob object and then ftp itYes, this is one of the options available. You may use DBAdapter to retrieve the values from DB and then FTP them to the provider's server. You may refer -
http://download.oracle.com/docs/cd/E17904_01/integration.1111/e10231/adptr_db.htm#BGBBHJGC
Regards,
Anuj -
Can we extract blob objects from sql database to a human readable format?
Hi All,
I have question How can we extract
blob objects from Sql database to human readable format ?
Blob includes Images, text and docs.
ThanksĀ
Moug
Best Regards MougOne thing you can do if its sql 2012 or later is to load the blob data to FileTable created in database. Then you would be able to physically browse to directory it points and see all files in its native format.
see this for more details
http://visakhm.blogspot.in/2012/07/working-with-filetables-in-sql-2012.html
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Make java.sql.Blob object from java serialized object
I have an ImageIcon which I get from an applet. It gets passed to a servlet. Now, I want to turn the ImageIcon into a blob object so that I can insert it into a database (as/400). How do I do that?
Hi there,
NORMALLY this is a 2-step process:
1.) Convert the ImageIcon into a byte-array
2.) Write the byte-array into the database/blob
For step 1 (this code is 'freehand'):
=====================================
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.write(myImageIcon);
oos.close();
byte[] data = bos.getBytes();
For step 2:
============
This is often database specific, but normally you select a column of a record for update, get the blob-object from the resultset and start writing bytes to it.
BUTTTTTTTT Consider this alternate approach: Assuming the image that is being sent is always small in size, you may simply chose to base-64 encode it and store the resultant string in a varchar column. When you read it back, base-64 decode it. Although the encoding/decoding may appear to be an overhead, I'll bet you it's much faster than blob-level access, both for reads and writes. It's also portable (code-wise) and you can update images through a simple UPDATE statement. In fact, if your database supports it, you could even have a default value for the column (a default image)... -
Hello,
Did any one have experience table re-org with BLOB object column?
Please let me know the best way doing it to claiming space.
I appreicate your help.
thanks
-AVselect 'alter table '||table_name||' move tablespace YOUR_TS'||chr(10)||
'LOB ('||column_name||') store as '||segment_name||chr(10)||
'(tablespace YOUR_TS);'
from user_lobs
/ -
Embed blob object into HTML region
Hi everyone!
I am interested in embedding a .swf file into an HTML region in ApEx. It's real easy when the source is a file or http server. However, could this be done if the source was a blob stored in the database?
Below is the code that works for me now in the HTML region, but I wonder if I could get the embed code to extract the source file from the database instead of a file server.
<object width="1024" height="768">
<param name="movie" value="http://webfiles.abc.com/level2/some_xcelsius_dashboard.swf">
<embed src="http://webfiles.abc.com/level2/some_xcelsius_dashboard.swf" width="1024" height="768">
</embed>
</object>
Thanks!!!
-RudyHi
Yes, that is easily done. See this doc on how to download a blob from a table:
Link
When you have created your download function, put a reference to it in the src= parameter.
Luis -
How to return new blob object?
Hi,
I am trying to find documentation on how to return a custom abstract data type (ADT) using the CREATE TYPE... and BLOB interface.
How can I return a new object type defined inside a blob. Can I return a blob (without initializing the lob locator first)?
Please advise.Hi,
Please check the below link.
http://docs.oracle.com/cd/E24693_01/appdev.11203/e17126/create_type.htm
Regards,
Sailaja -
Display BLOB objects (doc, pdf, jpg, etc) in Browser
Hello.
I need help retrieving BLOBs from my DB and displaying them on a browser using Java (or JSP). The BLOB can contain any types of file form (such as pdf, doc, xls, jpeg,etc).
null<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by LP:
Hello.
I need help retrieving BLOBs from my DB and displaying them on a browser using Java (or JSP). The BLOB can contain any types of file form (such as pdf, doc, xls, jpeg,etc).
<HR></BLOCKQUOTE>
null -
Displaying Blob Objects In A Report
Does anyone know how to generate a report in Portal that displays gif images which are saved in my database as a BLOB type in a simple report? I would like the report to display the images from this table at least 20 images per page and then allow the user to click next for the next 20. I was able to do this using a dynamic html portlet. But this required too much coding. Just curious if there was an easier way. Any help on this would be appreciated.
http://oracle.com/forums/thread.jsp?forum=7&thread=184943&message=486380
-
In one of the tabel we store blob column. This column stores file types like .doc,docx,xkls,tiff,jpg,pdf etc. The problem is as there are more usage of this tabel the size of hte tablespace is increasing significantly. Is there any way that these file size can be compressed so that my db storage is efficiently utilized>
Any other option to save size of the table space is also helpful.
Thanks in advanceIf you're still on 9.2, you don't have a lot of options, certainly no built-in options that would avoid making changes to queries. The UTL_COMPRESS package wasn't available yet and SecureFile LOBs certainly weren't available yet. That would leave the option of writing a Java stored procedure that did the compression and decompression.
Of course, if you wrote your own compress and decompress methods, you could make the decompression more or less seamless by putting the decompress method in a view and just referencing the view.
Justin
Maybe you are looking for
-
Hi, I would like to create a view from 4 different tables. How do I do it?. Say for example, I need user_id from table A which has the trans_id in table B and C. and I need to get a admin_id from table D and show these related fields in one single ro
-
Unwanted space around SWF inserts
This seems pretty easy but I can't find the problem. I am updating older sites and re-inserting swf animations. On every site the header wraps around to a second row when I insert the swf. I have a link to an example page below. These older sites wer
-
Do I need to put a tag on making a layout editable on iBooks Author?
Hello, I am teaching iBooks Author. And one of my students asked me why there is a tag to make a layout editable on iBooks Author. So I tried to figure out the objective of using a tag on iBooks Author. But, I haven't found the reason that we put a t
-
Unique Session en web application?? How?
How can i to force in my web application that my clients can only loggon one time at same time?, local vars in the application? if the client shutdown de PC?, i use OID for authentication, any way? Any data, url? Thanks
-
ArrayCollection could not be found.
hi i have import framework.swc, and mx.swc files in flash but still ArrayCollection class is not found VerifyError: Error #1014: Class mx.collections::ArrayCollection could not be found.