Skip to content
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

Added final blocks to close the db connection #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/main/java/com/bittercode/service/impl/BookServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ public Book getBookById(String bookId) throws StoreException {

book = new Book(bCode, bName, bAuthor, bPrice, bQty);
}


} catch (SQLException e) {

} finally {
try {
con.close();
} catch (SQLException e){

}
}
return book;
}
Expand All @@ -82,6 +90,12 @@ public List<Book> getAllBooks() throws StoreException {
}
} catch (SQLException e) {

} finally {
try {
con.close();
} catch (SQLException e){

}
}
return books;
}
Expand All @@ -100,6 +114,12 @@ public String deleteBookById(String bookId) throws StoreException {
} catch (Exception e) {
response += " : " + e.getMessage();
e.printStackTrace();
} finally {
try {
con.close();
} catch (SQLException e){

}
}
return response;
}
Expand All @@ -122,6 +142,12 @@ public String addBook(Book book) throws StoreException {
} catch (Exception e) {
responseCode += " : " + e.getMessage();
e.printStackTrace();
} finally {
try {
con.close();
} catch (SQLException e){

}
}
return responseCode;
}
Expand All @@ -139,6 +165,12 @@ public String updateBookQtyById(String bookId, int quantity) throws StoreExcepti
} catch (Exception e) {
responseCode += " : " + e.getMessage();
e.printStackTrace();
} finally {
try {
con.close();
} catch (SQLException e){

}
}
return responseCode;
}
Expand Down Expand Up @@ -166,6 +198,12 @@ public List<Book> getBooksByCommaSeperatedBookIds(String commaSeperatedBookIds)
}
} catch (SQLException e) {

} finally {
try {
con.close();
} catch (SQLException e){

}
}
return books;
}
Expand All @@ -186,6 +224,12 @@ public String updateBook(Book book) throws StoreException {
} catch (Exception e) {
responseCode += " : " + e.getMessage();
e.printStackTrace();
} finally {
try {
con.close();
} catch (SQLException e){

}
}
return responseCode;
}
Expand Down