Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Oracle/OAS
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Oracle/OAS
write a bytearray to an oracle db
snoofle
Greenhorn
Posts: 26
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hello all,
i have a function to generate a pdf with the pdflib
byte[] bytebuffer=null; try { pdflib pdf = new pdflib(); pdf.open_file(""); pdf.begin_page(842,595); PDFlibHelper.PDF_set_information(pdf); PDFlibHelper.PDF_draw_pageheader(pdf,"",""); pdf.end_page(); pdf.close(); bytebuffer = pdf.get_buffer(); } catch (Exception e) { e.printStackTrace(); }
then i want to store the bytebuffer = pdf.get_buffer(); into an oracle database with this script:
public final static int writeBytetoBlob( byte [] bytedata, String contenttype, String filename) { try { Connection connection = DataSourceConnection.getConnection(""); connection.setAutoCommit(false); Blob blob = null; Statement statement = connection.createStatement(); OracleResultSet resultset = null; OutputStream outputstream = null; statement.executeUpdate( "INSERT INTO MEDIA values ('1','test.pdf','application/pdf','test.pdf',empty_blob()) "); (OracleResultSet) statement.executeQuery( "SELECT DATA FROM MEDIA WHERE ID='1' FOR UPDATE"); resultset.next(); BLOB blobdata = resultset.getBLOB("DATA"); outputstream = blobdata.getBinaryOutputStream(); outputstream.write(bytedata); outputstream.flush(); outputstream.close(); connection.commit(); connection.setAutoCommit(true); connection.close(); } catch (Exception e) { log4jcategory.error("sqlqueryhelper::writebytetoblob:"+e.toString()); } return 0; }
when i then try to display the result with this
servlet then i get no pdf file public void performTask( javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException { InputStream in = null; Blob blob = null; java.sql.Connection connection = null; try { connection = DataSourceConnection.getConnection(); Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("SELECT DATA,CONTENTTYPE FROM MEDIA WHERE ID=1"); if (rs.next()) { blob = rs.getBlob(1); in = blob.getBinaryStream(); response.setContentType(rs.getString(2)); } OutputStream out = response.getOutputStream(); int bufferSize = ((oracle.sql.BLOB) blob).getBufferSize(); byte[] b = new byte[bufferSize]; int count = in.read(b, 0, (int) bufferSize); int pos = 0; while (count != -1) { out.write(b, 0, count); pos += count; count = in.read(b, 0, (int) bufferSize); } out.close(); out.flush(); connection.close(); } catch (Exception e) { } finally { in.close(); } }
i get no pdf file displayed
has anybody an idea where my error is ?
tia
andreas spiessl
snoofle
Greenhorn
Posts: 26
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hello all,
sorry wrong forum ...
should be in Oracle / OAS
andreas spiessl
Get off me! Here, read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Upload Download File
Retreving PDF File from Database using Java
write a bytearray to an oracle db
Reading From a Binary Large Object(BLOB)
Connection pooling issue in Apache 6.0
More...