|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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(); |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Uploading a blob to a oracle DB |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|