sqlStr="UPDATE "+tableName+" SET "+fieldName+"=empty_blob() WHERE "+idName+"="+idValue;
try{
stmt=conn.prepareStatement(sqlStr);
stmt.execute();
stmt.clearParameters();
stmt = conn.prepareStatement("SELECT "+fieldName+" FROM "+tableName+" WHERE "+idName+" = ? FOR UPDATE",ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
stmt.setInt(1,idValue);
rs = stmt.executeQuery();
if (rs.next()){
// Initialization
try{
mySmartUpload.initialize(pageContext);
}catch(ServletException e){
System.out.println(e);
}
// Upload
try{
mySmartUpload.upload();
}catch(SmartUploadException e){
System.out.println(e);
}catch(IOException e){
System.out.println(e);
}catch(ServletException e){
System.out.println(e);
}
// upload file in the DB if this file is not missing
if (!mySmartUpload.getFiles().getFile(0).isMissing()){
try {
mySmartUpload.getFiles().getFile(0).fileToOracleField(rs,fieldName);
rs.updateRow();
} catch(Exception e) {
System.out.println("An error occurs : " + e.toString());
}
}
}
conn.commit();
rs.close();
stmt.close();
conn.close();
}catch(SQLException e){
System.out.println(e.toString());
}
try{
stmt=conn.prepareStatement(sqlStr);
stmt.execute();
stmt.clearParameters();
stmt = conn.prepareStatement("SELECT "+fieldName+" FROM "+tableName+" WHERE "+idName+" = ? FOR UPDATE",ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
stmt.setInt(1,idValue);
rs = stmt.executeQuery();
if (rs.next()){
// Initialization
try{
mySmartUpload.initialize(pageContext);
}catch(ServletException e){
System.out.println(e);
}
// Upload
try{
mySmartUpload.upload();
}catch(SmartUploadException e){
System.out.println(e);
}catch(IOException e){
System.out.println(e);
}catch(ServletException e){
System.out.println(e);
}
// upload file in the DB if this file is not missing
if (!mySmartUpload.getFiles().getFile(0).isMissing()){
try {
mySmartUpload.getFiles().getFile(0).fileToOracleField(rs,fieldName);
rs.updateRow();
} catch(Exception e) {
System.out.println("An error occurs : " + e.toString());
}
}
}
conn.commit();
rs.close();
stmt.close();
conn.close();
}catch(SQLException e){
System.out.println(e.toString());
}