Closing Database Connections in Java is Very Important.
This is a very important function as it closes the connection to the database server. Your script will still run if you do not include this function. And too many open MySQL connections can cause problems for your account. Thus it is a good practice to close the MySQL connection once all the queries are executed. Closing Database Connections in Java is Very Important. If you don't, there's a chance MySQL server will reach it's connection limit when the web server is under heavy usage.
![]() |
Closing Database Connections |
This is a very important function as it closes the connection to the database server. Your script will still run if you do not include this function. And too many open MySQL connections can cause problems for your account. Thus it is a good practice to close the MySQL connection once all the queries are executed. Closing Database Connections in Java is Very Important. If you don't, there's a chance MySQL server will reach it's connection limit when the web server is under heavy usage.
Closing Database Connections
public boolean checkLoginUser(String userInput) { Connection con = null; PreparedStatement pstmt = null; ResultSet rs = null; try { // Getting Connection con = ConnectionManager.getConnectionFromPool(); String query = "Your Query"; try { // Your Prepared Statement pstmt = con.prepareStatement(query); try { // Your Prepared ResultSet rs = pstmt.executeQuery(); while (rs.next()) { } } catch (Exception e) { e.printStackTrace(); } finally { if (rs != null) { rs.close(); rs = null; } } } catch (Exception e) { e.printStackTrace(); } finally { if (pstmt != null) { pstmt.close(); pstmt = null; } } } catch (Exception e) { e.printStackTrace(); } finally { try { if (con != null) { con.close(); con = null; } } catch (Exception e) { } } return false; }
Post a Comment