Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 8th, 2004, 12:39 PM
subpop subpop is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 subpop User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Uploading a blob to a oracle DB

I'm about to get crazy! I can't upload an image to a DB.. This is the code I've written:

Connection conn=null;
PreparedStatement stmt=null;
PreparedStatement stmt2=null;
ResultSet rs=null;
Hashtable params = new Hashtable();
FilePart image = null;
Blob dbBlob=null;
MultipartParser mp = new MultipartParser(request, 50*1024); // 50 Kb limit
Part part;


try {
conn=DBConnection.getConnection();
if(conn==null) return;
stmt = conn.prepareStatement(QueryStr1);
rs = stmt.executeQuery();
if (rs.next()) dbBlob = rs.getBlob(1);


while ((part = mp.readNextPart()) != null)
{
String name = part.getName();
if (part.isParam())
{
ParamPart paramPart = (ParamPart) part;
params.put(paramPart.getName(), paramPart.getStringValue());
}
else if (part.isFile())
{
image = (FilePart) part;
//At this point, if I write to response.getOutputStream() it shows the image, so the problem must be inserting the blob
if (image.writeTo(((oracle.sql.BLOB)dbBlob).getBinary OutputStream()) <= 0)
utils.Logs.log(1,"class Upload - Error subiendo la imagen 1");
}
}


stmt2 = conn.prepareStatement(QueryStr2);
stmt2.setBlob(1, dbBlob);
stmt2.setInt(2,id);
stmt2.executeUpdate();


response.setContentType("image/jpeg");
OutputStream stream = response.getOutputStream();
stream.write(dbBlob.getBytes((long)1,(int)dbBlob.l ength()));
stream.close();

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Uploading a blob to a oracle DB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT