Code example for PreparedStatement

Methods: setBooleansetDatesetDoublesetFloatsetIntsetLongsetShortsetStringsetTimestamp

0
	public static void insertJdbcTypeParameter( 
			PreparedStatement preparedStatement, int index, Object value)
			throws SQLException { 
		Class classType = value.getClass();
		if (classType.equals(int.class) || classType.equals(Integer.class))
			preparedStatement.setInt(index, (Integer) value);
		if (classType.equals(short.class) || classType.equals(Short.class))
			preparedStatement.setShort(index, (Short) value);
		else if (classType.equals(long.class) || classType.equals(Long.class))
			preparedStatement.setLong(index, (Long) value);
		else if (classType.equals(float.class) || classType.equals(Float.class))
			preparedStatement.setFloat(index, (Float) value);
		else if (classType.equals(double.class)
				|| classType.equals(Double.class))
			preparedStatement.setDouble(index, (Double) value);
		else if (classType.equals(String.class))
			preparedStatement.setString(index, (String) value);
		else if (classType.equals(Date.class))
			preparedStatement.setDate(index, new java.sql.Date(((Date) value)
					.getTime()));
		else if (classType.equals(Timestamp.class))
			preparedStatement.setTimestamp(index, (Timestamp) value);
		else if (classType.equals(char.class)
				|| classType.equals(Character.class))
			preparedStatement.setString(index, value.toString());
		else if (classType.equals(boolean.class)
				|| classType.equals(Boolean.class))
			preparedStatement.setBoolean(index, (Boolean) value);
		else 
			throw new HiveRuntimeException("No known database type for class " 
					+ classType.getCanonicalName(), null);
	}