Created
November 28, 2017 07:11
-
-
Save anozimada/d717523951b7f85b524ded2113e47695 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.adempiere.com/ADempiere_Best_Practices#How_to_use_PreparedStatement.2FResultSet_.3F | |
// How to use PreparedStatement/ResultSet ? | |
final String sql = "''your SQL SELECT code''"; | |
PreparedStatement pstmt = null; | |
ResultSet rs = null; | |
try | |
{ | |
pstmt = DB.prepareStatement(sql, trxName); | |
DB.setParameters(pstmt, new Object[]{...''parameters''...}); | |
rs = pstmt.executeQuery(); | |
while(rs.next()) | |
{ | |
''// process fetched row'' | |
} | |
} | |
// If your method is not throwing Exception or SQLException you need this block to catch SQLException | |
// and convert them to unchecked DBException | |
catch (SQLException e) | |
{ | |
throw new DBException(e, sql); | |
} | |
// '''ALWAYS''' close your ResultSet in a finally statement | |
finally | |
{ | |
DB.close(rs, pstmt); | |
rs = null; pstmt = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment