Code example for PreparedStatement

Methods: executeUpdate, setDouble, setInt, setNull, setString

0
 
		try { 
			updateStmt = connection.prepareStatement(DB_QUERY_UPDATE);
			// set the params 
			if (entity.getSmaliClass() != null) {
				updateStmt.setInt(++index, entity.getSmaliClass().getId()); // the class it
																	// belongs 
																	// to 
			} else { 
				updateStmt.setNull(++index, Types.INTEGER); // the class it belongs to
			} 
 
			if (entity.getCodeLines() != null
					&& entity.getCodeLines().getFirst() != null) {
				updateStmt.setInt(++index, entity.getCodeLines().getFirst().getLineNr()); // the
																				// initial 
																				// line 
																				// of 
																				// code 
			} else { 
				updateStmt.setNull(++index, Types.INTEGER); // the initial line of code
			} 
 
			if (entity.getCodeLines()!=null) {
				updateStmt.setInt(++index, entity.getCodeLines().size()); //the number of lines of code
			}else 
			{ 
				updateStmt.setNull(++index, Types.INTEGER); //the number of lines of code
			} 
			 
			updateStmt.setDouble(++index, entity.arithOps()); //the fraction of arithemtic operations
			 
			updateStmt.setNull(++index, Types.VARCHAR); //there is no getter for the fuzzy hash
			 
			if(entity.getName()!=null)
			{ 
				updateStmt.setString(++index, entity.getName());
			}else 
			{ 
				updateStmt.setNull(++index, Types.VARCHAR);
			} 
			if(entity.getParameterString()!=null)
			{ 
				updateStmt.setString(++index, entity.getParameterString());
			}else 
			{ 
				updateStmt.setNull(++index, Types.VARCHAR);
			} 
			 
			 
			if(entity.getReturnValueString()!=null)
			{ 
				updateStmt.setString(++index, entity.getReturnValueString());
			}else 
			{ 
				updateStmt.setNull(++index, Types.VARCHAR);
			} 
			updateStmt.setNull(++index, Types.VARCHAR	); //FIXME there is no getter for the cfg path
			updateStmt.setInt(++index, entity.getId());
			recordsUpdated = updateStmt.executeUpdate();
			// this should affect at most one record 
			if (recordsUpdated == 0) {
				throw new NoSuchEntityException(); 
			} else if (recordsUpdated == 1) {
				success = true;