import java.sql.Types;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.SqlUpdate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
class Main {
public static void main(String args[]) throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("context.xml", Main.class);
DataSource dataSource = (DataSource) ac.getBean("dataSource");
//DataSource mysqlDataSource = (DataSource) ac.getBean("mysqlDataSource");
NamedInsert namedInsert = new NamedInsert(dataSource);
Map<String, Object> parameterMap = new HashMap<String, Object>();
parameterMap.put("id", 6L);
parameterMap.put("firstName", "A");
parameterMap.put("lastName", "B");
parameterMap.put("lastLogin", null);
parameterMap.put("comments", null);
namedInsert.updateByNamedParam(parameterMap);
}
}
class NamedInsert extends SqlUpdate {
private static final String SQL = "insert into t_customer (id, first_name, last_name, last_login, " +
"comments) values (:id, :firstName, :lastName, :lastLogin, :comments)";
NamedInsert(DataSource dataSource) {
super(dataSource, SQL);
declareParameter(new SqlParameter(Types.INTEGER));
declareParameter(new SqlParameter(Types.VARCHAR));
declareParameter(new SqlParameter(Types.VARCHAR));
declareParameter(new SqlParameter(Types.TIMESTAMP));
declareParameter(new SqlParameter(Types.CLOB));
}
}
|