** Как передать тип Enum в базу данных ? Используя java.sql.Types ?
Вся проблема в последнем типе COUPON_TYPE .
if(findInDatabase(mappedObject) == NOT_EXIST){
String query = "INSERT INTO coupons (COUPON_ID,COUPON_AMOUNT,EXPIRATION_DATE,COUPON_IMAGE,COUPON_MESSAGE,COUPON_PRICE,RELEASE_DATE,COUPON_TITLE,COUPON_TYPE) values(?,?,?,?,?,?,?,?,?)";
List<SqlParameter> types = getParametersForQuery(new Object[]{Types.BIGINT,Types.BIGINT,Types.DATE,Types.VARCHAR,Types.VARCHAR,Types.DOUBLE,Types.DATE,Types.VARCHAR,Types.JAVA_OBJECT},9);
csQuery(query,types).updateDatabase(new Object[]{coupon.getId(), coupon.getAmount(), coupon.getEndDate(),coupon.getImage(), coupon.getMessage(), coupon.getPrice(), coupon.getStartDate(), coupon.getTitle(), coupon.getType()});
public enum CouponType {
RESTAURANTS,ELECTRICITY,FOOD,HEALTH,SPORTS,CAMPING,TRAVELING
}
Exception:
Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: SQL [INSERT INTO coupons (COUPON_ID,COUPON_AMOUNT,EXPIRATION_DATE,COUPON_IMAGE,COUPON_MESSAGE,COUPON_PRICE,RELEASE_DATE,COUPON_TITLE,COUPON_TYPE) values(?,?,?,?,?,?,?,?,?)]: given 9 parameters but expected 8