-
Notifications
You must be signed in to change notification settings - Fork 2
Spring base sw #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: JavaBase
Are you sure you want to change the base?
Spring base sw #15
Changes from 1 commit
10393c8
669ab96
3855223
255559f
f5985d1
7ccbd72
37d9be5
2088ede
450b9b4
8f4c39d
3b8d39d
70767e8
a9ee984
ba63810
259572a
7cefc4b
ed97f88
4f1b409
982bfb7
4fcfc13
eedeacf
86fc5fa
efe032e
f06f468
10c7734
0ece409
c53aaf1
278c4f9
a0c8825
0c34ffb
4fccf07
e2c6274
782e1e6
9a186b8
bd3f91a
fa8f0ef
caaa8c2
45f9a15
ef028cb
bd962c3
807d328
4adc69e
4cdf4c9
77bbc75
0b6c23d
a7a14fa
fe8832f
e88b640
398462c
3ee673b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,18 @@ public class JdbcBookRepository implements BookRepository { | |
| private static Statement statement; | ||
| private static PreparedStatement preparedStatement; | ||
|
|
||
| private Book setBook(ResultSet resultSet) throws SQLException { | ||
| Book book = new Book(); | ||
|
|
||
| book.setTitle(resultSet.getString("title")); | ||
| book.setIsbn(resultSet.getString("isbn")); | ||
| book.setAuthor(resultSet.getString("author")); | ||
| book.setCategory(BookCategory.valueOf(resultSet.getString("book_category"))); | ||
| book.setStatus(BookStatus.valueOf(resultSet.getString("book_status"))); | ||
|
|
||
| return book; | ||
| } | ||
|
|
||
| public JdbcBookRepository(){ | ||
| try { | ||
| connection = DriverManager.getConnection(DATABASE_URL); | ||
|
|
@@ -54,13 +66,13 @@ public Book save(Book book) { | |
|
|
||
| } catch (SQLException e) { | ||
| System.out.println(e.getMessage()); | ||
| return null; | ||
| } | ||
| return null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드가 null을 반환하는 경우는 없어야 합니다. 이 사항은 모든 메서드에 일괄 적용해주시기 바랍니다. |
||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public Book findByISBN(String isbn) { | ||
| Book book = new Book(); | ||
|
|
||
| String sql = "SELECT * from Book where isbn = ?"; | ||
|
|
||
|
|
@@ -72,23 +84,23 @@ public Book findByISBN(String isbn) { | |
| ResultSet resultSet = preparedStatement.executeQuery(); | ||
|
|
||
| if (resultSet.next()) { | ||
| book.setTitle(resultSet.getString("title")); | ||
| book.setIsbn(resultSet.getString("isbn")); | ||
| book.setAuthor(resultSet.getString("author")); | ||
| book.setCategory(BookCategory.valueOf(resultSet.getString("book_category"))); | ||
| book.setStatus(BookStatus.valueOf(resultSet.getString("book_status"))); | ||
|
|
||
| Book book = setBook(resultSet); | ||
|
|
||
| System.out.println(book.getTitle() + " 책 조회 성공"); | ||
|
|
||
| return book; | ||
|
|
||
| } else { | ||
| System.out.println("책을 찾을 수 없습니다."); | ||
| } | ||
|
|
||
| return book; | ||
|
|
||
| } catch (SQLException e) { | ||
| System.out.println(e.getMessage()); | ||
| return null; | ||
| } | ||
| return null; | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -125,12 +137,7 @@ public List<Book> findAll() { | |
| ResultSet resultset = statement.executeQuery(sql); | ||
|
|
||
| while (resultset.next()) { | ||
| Book book = new Book(); | ||
| book.setTitle(resultset.getString("title")); | ||
| book.setIsbn(resultset.getString("isbn")); | ||
| book.setAuthor(resultset.getString("author")); | ||
| book.setCategory(BookCategory.valueOf(resultset.getString("book_category"))); | ||
| book.setStatus(BookStatus.valueOf(resultset.getString("book_status"))); | ||
| Book book = setBook(resultset); | ||
|
|
||
| System.out.println("모든 책 조회 성공"); | ||
|
|
||
|
|
@@ -139,9 +146,12 @@ public List<Book> findAll() { | |
|
|
||
| resultset.close(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. close 메서드는 try-catch의 finally 문에서 호출하는 것이 좋아보입니다. (예외가 발생하는 경우에도 close 할 수 있어야 함.) 또, static이 붙은 경우에는 그 특성을 잘 고려하여 close를 호출 할 것인지를 잘 생각해야 합니다. |
||
| statement.close(); | ||
| } catch (SQLException e){ | ||
|
|
||
| return books; | ||
|
|
||
| } catch (SQLException e) { | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| return books; | ||
| return null; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
book의 setter 메서드에 값을 입력할 때 내부적으로 valueOf와 getter 호출이 일어나고 있습니다. 이는 앞에서 간단한 변수로 빼두어 사용하면 간결할 것 같습니다.