List of usage examples for java.sql ResultSet close
void close() throws SQLException;
ResultSet
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. From source file:org.zenoss.zep.dao.impl.DaoUtils.java
/** * Returns a list of column names in the specified table. * * @param dataSource DataSource to use./*from w w w. j a v a 2s.co m*/ * @param tableName Table name. * @return A list of column names in the table. * @throws MetaDataAccessException If an exception occurs. */ public static List<String> getColumnNames(final javax.sql.DataSource dataSource, final String tableName) throws MetaDataAccessException { final List<String> columnNames = new ArrayList<String>(); JdbcUtils.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() { @Override public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException { ResultSet rs = dbmd.getColumns(null, null, tableName, null); while (rs.next()) { String columnName = rs.getString("COLUMN_NAME"); columnNames.add(columnName); } rs.close(); return null; } }); return columnNames; }
From source file:local.Statistics.MostSellCars.java
/** * @param args the command line arguments *///from www .j a v a2 s. c o m public static void carrosMasVendidos() { Graficas_DAO gr = new Graficas_DAO(); //obtencion de datos ResultSet rs = gr.getgraficaautomas(); try { String nameAuto; int quantitySales; Object[] fila = new Object[3]; DefaultPieDataset data = new DefaultPieDataset(); while (rs.next()) { nameAuto = rs.getString(3); quantitySales = rs.getInt(1); data.setValue(nameAuto, quantitySales); } JFreeChart chart = ChartFactory.createPieChart("GRAFICAS AUTOS MAS VENDIDOS", data, true, true, false); ChartFrame frame = new ChartFrame("Autos mas vendidos", chart); frame.pack(); frame.setVisible(true); rs.close(); gr.close(); } catch (SQLException ex) { Logger.getLogger(MostSellCars.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.concursive.connect.web.modules.search.utils.SearchUtils.java
/** * Generates a list of projects that the user has access to * * @param db/*from ww w . java2 s. c o m*/ * @param userId * @param specificProjectId * @param specificCategoryId * @return * @throws SQLException */ public static String generateValidProjects(Connection db, int userId, int specificProjectId, int specificCategoryId) throws SQLException { if (userId < 1) { return ""; } // @todo get ids from user cache // @update cache everytime a user is added or removed from a project team // get the projects for the user // get the project permissions for each project // if user has access to the data, then add to query StringBuffer projectList = new StringBuffer(); PreparedStatement pst = db .prepareStatement("SELECT project_id " + "FROM project_team " + "WHERE user_id = ? " + "AND status IS NULL " + (specificProjectId > -1 ? "AND project_id = ? " : "") + (specificCategoryId > -1 ? "AND project_id IN (SELECT project_id FROM projects WHERE category_id = ?) " : "")); int i = 0; pst.setInt(++i, userId); if (specificProjectId > -1) { pst.setInt(++i, specificProjectId); } if (specificCategoryId > -1) { pst.setInt(++i, specificCategoryId); } ResultSet rs = pst.executeQuery(); while (rs.next()) { int projectId = rs.getInt("project_id"); // these projects override the lower access projects if (projectList.length() > 0) { projectList.append(" OR "); } projectList.append(projectId); } rs.close(); pst.close(); return projectList.toString(); }
From source file:net.tirasa.ilgrosso.resetdb.Main.java
private static void resetPostgreSQL(final Connection conn) throws Exception { final Statement statement = conn.createStatement(); final ResultSet resultSet = statement .executeQuery("SELECT 'DROP TABLE ' || c.relname || ' CASCADE;' FROM pg_catalog.pg_class c " + "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace " + "WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') " + "AND pg_catalog.pg_table_is_visible(c.oid)"); final List<String> drops = new ArrayList<String>(); while (resultSet.next()) { drops.add(resultSet.getString(1)); }/*from w ww. j ava 2 s . com*/ resultSet.close(); for (String drop : drops) { statement.executeUpdate(drop.substring(0, drop.length() - 1)); } statement.close(); conn.close(); }
From source file:com.uber.hoodie.hive.HoodieHiveClient.java
private static void closeQuietly(ResultSet resultSet, Statement stmt) { try {/* w w w. j a va 2 s .c o m*/ if (stmt != null) { stmt.close(); } if (resultSet != null) { resultSet.close(); } } catch (SQLException e) { LOG.error("Could not close the resultset opened ", e); } }
From source file:com.useekm.indexing.postgis.IndexedStatement.java
/** * Close, but ignore null input and catch and log resulting * {@link SQLException}s./*from w w w . ja va 2 s .com*/ */ public static void closeQuietly(ResultSet results) { try { if (results != null) // can't check isClosed when using dbcp // connection pooling results.close(); } catch (SQLException e) { LOG.error("could not close jdbc resultset", e); } }
From source file:genericepayadmin.AddIpBean.java
public static int getPages(Connection con) throws Exception { int totalcount = 0; PreparedStatement ps = null;//from w ww . ja va 2 s . co m ResultSet rs = null; try { String sql = "select ceil(count(*)/10) as totalpage from webservice_validator"; ps = con.prepareStatement(sql); rs = ps.executeQuery(); if (rs.next()) { totalcount = rs.getInt("totalpage"); } } catch (Exception e) { System.out.println(e.getMessage()); } finally { try { if (ps != null) ps.close(); if (rs != null) rs.close(); } catch (Exception e) { System.out.println(e.getMessage()); } } return totalcount; }
From source file:gridool.util.jdbc.JDBCUtils.java
/** * Close a <code>ResultSet</code>, avoid closing if null. *//*from w ww . j av a 2s .c om*/ public static void closeAll(ResultSet rs) throws SQLException { if (rs != null) { Statement stmt = rs.getStatement(); if (stmt != null) { Connection conn = stmt.getConnection(); stmt.close(); closeQuietly(conn); } else { rs.close(); } } }
From source file:com.mirth.connect.server.controllers.tests.TestUtils.java
public static boolean channelExists(String channelId) throws Exception { boolean exists = false; Connection connection = getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT 1 FROM channels WHERE channel_id = ?"); statement.setString(1, channelId);/*from ww w . j a va 2s. c om*/ ResultSet result = statement.executeQuery(); if (result.next()) { exists = true; } result.close(); connection.close(); return exists; }
From source file:net.sf.webphotos.tools.Thumbnail.java
/** * Abre uma conexo com o banco de dados atravs da classe BancoImagem, * busca um lote de imagens e faz thumbs para todas as fotos. No possui * utilizaes.//from ww w.ja v a 2s .c o m */ public static void executaLote() { net.sf.webphotos.BancoImagem db = net.sf.webphotos.BancoImagem.getBancoImagem(); try { db.configure("jdbc:mysql://localhost/test", "com.mysql.jdbc.Driver"); BancoImagem.login(); java.sql.Connection conn = BancoImagem.getConnection(); java.sql.Statement st = conn.createStatement(); java.sql.ResultSet rs = st.executeQuery("select * from fotos"); int albumID, fotoID; String caminho; while (rs.next()) { albumID = rs.getInt("albumID"); fotoID = rs.getInt("fotoID"); caminho = "d:/bancoImagem/" + albumID + "/" + fotoID + ".jpg"; makeThumbs(caminho); Util.out.println(caminho); } rs.close(); st.close(); conn.close(); } catch (Exception e) { e.printStackTrace(Util.err); } }