|
Code Listing 2: Using OrdHttpUploadFormData to upload an HTML form
// Create an OrdHttpUploadFormData object and use it to parse the
// multipart/form-data message.
//
OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request );
formData.parseFormData( );
// Get the description, location, and photograph.
//
String id = formData.getParameter("id");
String description = formData.getParameter("description");
String location = formData.getParameter("location");
OrdHttpUploadFile photo = formData.getFileParameter("photo");
// Prepare and execute a SQL statement to insert a new row into
// the table and return the sequence number for the new row.
// Disable auto-commit to allow the LOB to be written correctly.
//
conn.setAutoCommit(false);
PreparedStatement stmt = conn.prepareStatement("insert into photo_album (id,
description, location, photo) " + " values (?, ?, ?, ORDSYS.ORDIMAGE.INIT( ))");
stmt.setString(1, id);
stmt.setString(2, description);
stmt.setString(3, location);
stmt.executeUpdate( );
// Prepare and execute a SQL statement to fetch the new OrdImage
// object from the database.
//
stmt = conn.prepareStatement("select photo from photo_album where id = ? for
update");
stmt.setString(1, id);
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (!rset.next( )){
throw new ServletException("new row not found in table");
}
OrdImage media = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( ));
// Load the photograph into the database and set the properties.
//
photo.loadImage(media);
// Prepare and execute a SQL statement to update the image object.
//
stmt = (OraclePreparedStatement)conn.prepareStatement("update photo_album set
photo = ? where id = ?");
stmt.setCustomDatum(1, media);
stmt.setString(2 id);
stmt.execute( );
stmt.close( );
// Commit the changes.
//
conn.commit( );
|