M
M
Maks Burkov2017-03-31 15:56:13
Java
Maks Burkov, 2017-03-31 15:56:13

How correctly to make query in my case?

** How to pass the Enum type to the database ? Using java.sql.Types ?
The whole problem is in the last type 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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
al_gon, 2017-03-31
@Maks00088

Enum is a String
www.java2s.com/Code/Java/Database-SQL-JDBC/Enumera...
But the problem is different, you have less than expected values.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question