Tuesday, January 26, 2016


  1. Class with Static functions:
    If with high calling frequency, we need to refactor to non-static function, parse with different object of the Class.
  2. Path Separator VS separator
    File.pathSeparator: separate file path in PATH environment vairable, ";"
    File.separator: "/" or "\" to split up the path of a file
  3. Close the resource with the block
    Example: SQL Clean way to close ResultSet
    Use CachedRowSet
     public static ResultSet executeQuery(String sql, String[] parameters){
      DataSource ds = DBConnector.setupDataSource();
      try (
       Connection conn = ds.getConnection();
       PreparedStatement ps = createPreparedStatement(conn,sql,parameters);
       ResultSet rs = ps.executeQuery();
      ) {
       CachedRowSet rowset = new CachedRowSetImpl();
       return rowset;
      } catch (SQLException e) {
       Logger lgr = Logger.getLogger(SqlHelper.class);
      return null;

No comments:

Post a Comment