private void execute(String sql) { if (sql.trim().isEmpty()) { return; } long time = System.currentTimeMillis(); try { ResultSet rs = null; try { if (stat.execute(sql)) { rs = stat.getResultSet(); int rowCount = printResult(rs, listMode); time = System.currentTimeMillis() - time; println("(" + rowCount + (rowCount == 1 ? " row, " : " rows, ") + time + " ms)"); } else { int updateCount = stat.getUpdateCount(); time = System.currentTimeMillis() - time; println("(Update count: " + updateCount + ", " + time + " ms)"); } } finally { JdbcUtils.closeSilently(rs); } } catch (SQLException e) { println("Error: " + e.getMessage()); if (listMode) { e.printStackTrace(err); } return; } out.println(); }
/** * Open a new database connection with the given settings. * * @param driver the driver class name * @param url the database URL * @param user the user name * @param password the password * @return the database connection */ public static Connection getConnection(String driver, String url, String user, String password) throws SQLException { Properties prop = new Properties(); if (user != null) { prop.setProperty("user", user); } if (password != null) { prop.setProperty("password", password); } return getConnection(driver, url, prop); }
} finally { close(); JdbcUtils.closeSilently(rs);
throw DbException.convert(e); } finally { JdbcUtils.closeSilently(rs);