Code example for PreparedStatement

Methods: executeUpdate, setFloat, setInt, setString, toString

0
			String updateQuery = ImageTag.INSERT_TAGS;
			//INSERT_WIDGETS = "INSERT INTO table  (file_id, patient_id, username, x_origin, y_origin, shape_x, shape_y, width, height, zoom, color, shape_type  ) values (?,?,?,?,?) "; 
 
			prep= dbConn.prepareStatement(updateQuery);
			 
			prep.setInt(1, fileId);
			prep.setInt(2, patientId);
			prep.setString(3, userName);
			prep.setFloat(4, xOrigin);
			prep.setFloat(5, yOrigin);
			prep.setFloat(6, shapeX);
			prep.setFloat(7, shapeY);
			prep.setFloat(8, width);
			prep.setFloat(9, height);
			prep.setFloat(10, zoom);
			prep.setString(11, color);
			prep.setString(12, type);
			prep.setString(13, note);
			// 
			log.finer("ImageTag saveAnnotations sql " + prep.toString() );
			 
			int rtn = prep.executeUpdate();
			if (rtn < 0)
			{ 
				DatabaseUtility.close(prep);
				dbConn.close();
				return WebUtils.buildErrorJson( "Problem on updating annotation data into the database " + prep.toString());
 
			} 
		} 
		catch (JSONException e) {
			// TODO Auto-generated catch block 
			log.severe("ImageTag saveAnnotations Problem on updating annotation data to database ." + e.getMessage() );
			 
			return WebUtils.buildErrorJson( "Problem on updating annotation data from database ." + e.getMessage());
 
		} 
		catch (SQLException e) {
			throw e;
		} 
		finally 
		{ 
			DatabaseUtility.close(prep);
			dbConn.close();
			 
		} 
		return ret;
	}