Skip to content

Commit

Permalink
Added JDBC files
Browse files Browse the repository at this point in the history
  • Loading branch information
nikunjmulani committed Oct 31, 2018
1 parent 4830398 commit 2e93a59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterUtils;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;

Expand All @@ -29,6 +30,8 @@ public JdbcTimeEntryRepository(DataSource dataSource) {
public TimeEntry create(TimeEntry timeEntry) {
KeyHolder generatedKeyHolder = new GeneratedKeyHolder();



jdbcTemplate.update(connection -> {
PreparedStatement statement = connection.prepareStatement(
"INSERT INTO time_entries (project_id, user_id, date, hours) " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.util.TimeZone;

@SpringBootApplication
Expand All @@ -21,9 +22,10 @@ public static void main(String[] args) {
}



@Bean
TimeEntryRepository timeEntryRepository() {
return new InMemoryTimeEntryRepository();
TimeEntryRepository timeEntryRepository(DataSource dataSource) {
return new JdbcTimeEntryRepository(dataSource);
}

@Bean
Expand Down

0 comments on commit 2e93a59

Please sign in to comment.