Announcement Announcement Module
Collapse
No announcement yet.
on duplicate - save me from my verbosity! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • on duplicate - save me from my verbosity!

    Here's a lot of parameter declaring? Am I missing something. Can anyone suggest a way to pare this lot down?

    TIA

    Code:
    class CardUpdate extends SqlUpdate {
    		public CardUpdate(DataSource dataSource) {
    			setDataSource(dataSource);
    			setSql("insert into card "
    					+ "(cardID, userName, bill_address1, bill_city, bill_country, bill_state, bill_zip, "
    					+ "currency, cc_expiryMonth,	cc_expiryYear,	cc_startsMonth,	cc_startsYear,	cc_number,	cc_SecurityNumber,	"
    					+ "customer_email, customer_firstname, customer_lastname,	customer_phone)	"
    					+ "values "
    					+ "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
    					+ "ON DUPLICATE KEY UPDATE bill_address1 = ?, bill_city = ?, bill_country = ?, bill_state = ?, bill_zip = ?, "
    					+ "	currency = ?, cc_expiryMonth = ?,	cc_expiryYear = ?,	cc_startsMonth = ?,	cc_startsYear = ?,	cc_number = ?,	cc_SecurityNumber = ?,	"
    					+ "	customer_email = ?, customer_firstname = ?,	customer_lastname = ?, customer_phone = ?");
    
    			declareParameter(new SqlParameter(Types.VARCHAR)); // cardID
    			declareParameter(new SqlParameter(Types.VARCHAR)); // userName
    			declareParameter(new SqlParameter(Types.VARCHAR)); // bill_address1
    			declareParameter(new SqlParameter(Types.VARCHAR)); // bill_city
    			declareParameter(new SqlParameter(Types.VARCHAR)); // bill_country
    			declareParameter(new SqlParameter(Types.VARCHAR)); // bill_state
    			declareParameter(new SqlParameter(Types.VARCHAR)); // bill_zip
    			declareParameter(new SqlParameter(Types.VARCHAR)); // currency
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_expiryMonth
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_expiryYear
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_startsMonth
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_startsYear
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_number
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_SecurityNumber
    			declareParameter(new SqlParameter(Types.VARCHAR)); // customer_email
    			declareParameter(new SqlParameter(Types.VARCHAR)); // customer_firstname
    			declareParameter(new SqlParameter(Types.VARCHAR)); // customer_lastname
    			declareParameter(new SqlParameter(Types.VARCHAR)); // customer_phone
    
    			declareParameter(new SqlParameter(Types.VARCHAR)); // bill_address1
    			declareParameter(new SqlParameter(Types.VARCHAR)); // bill_city
    			declareParameter(new SqlParameter(Types.VARCHAR)); // bill_country
    			declareParameter(new SqlParameter(Types.VARCHAR)); // bill_state
    			declareParameter(new SqlParameter(Types.VARCHAR)); // bill_zip
    			declareParameter(new SqlParameter(Types.VARCHAR)); // currency
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_expiryMonth
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_expiryYear
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_startsMonth
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_startsYear
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_number
    			declareParameter(new SqlParameter(Types.INTEGER)); // cc_SecurityNumber
    			declareParameter(new SqlParameter(Types.VARCHAR)); // customer_email
    			declareParameter(new SqlParameter(Types.VARCHAR)); // customer_firstname
    			declareParameter(new SqlParameter(Types.VARCHAR)); // customer_lastname
    			declareParameter(new SqlParameter(Types.VARCHAR)); // customer_phone
    			compile();
    		}
    
    		public int update(Card card) {
    			return update(new Object[] {LOTS MORE CODE HERE!!});
    		}

  • #2
    Hi

    if you would like to remove all this code, may be you can use Hibernate and call saveOrUpdate() method which will automatically check whether the record has to be updated/inserted.

    Hibernate is the simplest solution to reduce JDBC parameter code

    Comment


    • #3
      Something like Hibernate does make this much nicer. Wouldn't something like JdbcTemplate.update(..) be easier.
      http://www.springframework.org/docs/....Object[])

      Comment

      Working...
      X