https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/BeanPropertyRowMapper.html BeanPropertyRowMapper (Spring Framework 5.3.14 API) RowMapper implementation that converts a row into a new instance of the specified mapped target class. The mapped target class must be a top-level class and it must have a default or no-arg constructor. Column values are map..
DDL Create Table employee라는 이름의 테이블을 만듭니다. 컬럼은 id, name, contents 3개 입니다. if not exists 가 들어있어서 없을때만 create table을 실행하고 테이블이 존재한다면 실행하지 않습니다. .update()를 썼기 때문에 리턴값이 0입니다. public int createTable() { // table이 있는지 먼저 check return this.jdbcTemplate.update(String.format("create table if not exists employee(id bigint, name varchar, contents text)")); } With Primary Key public int createTable() { // t..
결론부터 이야기 하자면 Jdbc로 MySql의 Datetime타입에 값을 넣을 때 LocalDateTime을 이용하고 db에 insert할 때는 Timestamp로 바꿔서 합니다. 위 table의 created_at이 MySql datetime 타입 입니다. public class CarModel { private int id; private String name; private int level; private LocalDateTime createdAt; } Model은 LocalDateTime으로 했습니다. public void add(CarModel carModel) throws SQLException { this.jdbcContext.workWithStatementStrategy(new State..
Enum이란? Enum은 enumeration 에서 앞에 4글자 입니다. 보통 열거형이라고 번역 되어 있습니다. 어플리케이션이 복잡해지다 보면 에러가 날 가능성도 올라가는데 넣을 수 있는 값들을 Enum에 미리 지정 해놓고 그 값 말고 다른 값들을 넣지 못하게 하여 에러를 방지하는 목적으로 사용 합니다. 예를들면 계절은 4계절 뿐이고 요일도 월~일이렇게 7일뿐입니다. 그래서 이 밖에 값들을 입력 할 수 없게 미리 정해 놓는 것입니다. public enum Season { 봄(1), 여름(2), 가을(3), 겨울(4); private final int value; Season(int value) { this.value = value; } } 보통은 위와 같이 사용 합니다. public enum Season..
토비의 스프링3를 따라하면서 Spring버젼이 올라가면서 바뀐부분이 있어서 정리해서 올려놓습니다. 3장 Template queryForInt --> queryForObject 토비의스프링3를 따라하다가 JdbcContext를 JdbcTemplate으로 바꿔주는 구간에서 책이 오래 되었기 때문에 스프링을 최신버젼(저는 5버젼)을 쓰면 따라하기 힘든 구간이 나옵니다. public int getCount() throws SQLException { StatementStrategy st = new StatementStrategy() { @Override public PreparedStatement makePreparedStatement(Connection c) throws SQLException { Prepare..
Context는 '맥락'이라는 뜻 입니다. 여기에서 context는 JDBC를 이용해 DB를 업데이트 한다는 변하지 않는 맥락이 있습니다. 맥락은 스타벅스에서 커피를 주문 하는 것과 비유를 해보면 1.고객은 스타벅스 직원에게 메뉴들을 주문하고 2.직원은 전체 얼마인지 계산을 해서 고객에게 알려주고 3.고객은 결제를 하고 4.주문한 메뉴들이 만들어 지면 받아가는 맥락입니다. 여기에서 핵심 메소드는 executeSql입니다. executeSql은 Sql문을 받아서 실행을 해주는 역할을 하고 있습니다. public class JdbcContext JdbcContext클래스는 DataSource를 외부에서 받아주는 기능이 있고 executeSql은 workWithStatementStrategy에 Prepared..
ConnectionMaker에서 Datasource로 바꾸기 Toby Spring3에서 ConnectionMaker에서 DataSource로 넘어가는 과정이 있습니다. SimpleDriverDataSource는 'org.springframework:spring-jdbc:5.3.12' 가 필요 합니다. public class DaoFactory { private ConnectionMaker connectionMaker(){ BinaryConnectionMaker binaryConnectionMaker = new BinaryConnectionMaker(); return binaryConnectionMaker; } private DataSource dataSource() { SimpleDriverDataSou..
UserDao Test code 아래 4가지 항목을 test하는 test code 1.DummyData2.addAndGet3.Update4.getAll @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/applicationContext.xml") public class UserDaoJdbcTest { @Autowired private UserDao userDao; private User user1, user2, user3; @Before public void setUp() throws Exception { this.user1 = new User("oceanfog", "kyeongork", "1123", Level.BASIC, 1, 0, "o..
- Total
- Today
- Yesterday
- 싱가폴
- 개발자
- shellscript
- 도커티슈박스
- vim
- 도커티슈케이스
- 2017 티스토리 결산
- 도커각티슈케이스
- docker container
- 도커컨테이너
- Sh
- 도커각티슈박스
- docker container tissue
- docker container tissue box
- docker container whale
- docker container case
- Linux
- 이직
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |