List of usage examples for java.sql ResultSet next
boolean next() throws SQLException;
From source file:Main.java
private static void addChildren(Writer writer, ResultSet rs) throws SQLException, IOException { ResultSetMetaData metaData = rs.getMetaData(); int nbColumns = metaData.getColumnCount(); StringBuffer buffer = new StringBuffer(); while (rs.next()) { buffer.setLength(0);//from w w w.j a va2s. com buffer.append("<" + metaData.getTableName(1) + ">"); for (int i = 1; i <= nbColumns; i++) { buffer.append("<" + metaData.getColumnName(i) + ">"); buffer.append(rs.getString(i)); buffer.append("</" + metaData.getColumnName(i) + ">"); } buffer.append("</" + metaData.getTableName(1) + ">"); writer.write(buffer.toString()); } }
From source file:com.chiralbehaviors.CoRE.kernel.KernelUtil.java
static void alterTriggers(Connection connection, boolean enable) throws SQLException { for (String table : new String[] { "ruleform.agency", "ruleform.product", "ruleform.location" }) { String query = String.format("ALTER TABLE %s %s TRIGGER ALL", table, enable ? "ENABLE" : "DISABLE"); connection.createStatement().execute(query); }/*from w ww .ja v a 2s .c o m*/ ResultSet r = connection.createStatement().executeQuery(KernelUtil.SELECT_TABLE); while (r.next()) { String table = r.getString("name"); String query = String.format("ALTER TABLE %s %s TRIGGER ALL", table, enable ? "ENABLE" : "DISABLE"); connection.createStatement().execute(query); } r.close(); }
From source file:com.bluepandora.therap.donatelife.service.CheckService.java
public static boolean isDuplicateHospital(String mobileNumber, String hospitalId, DatabaseService dbService) { String query = GetQuery.getDuplicateHospitalGroupQuery(mobileNumber, hospitalId); //Debug.debugLog("DUPLICATE HOSPITAL QUERY: ", query); ResultSet result = dbService.getResultSet(query); boolean VALID_HOSPITAL = true; try {//from ww w . ja v a 2s. c om while (result.next()) { VALID_HOSPITAL = false; } } catch (SQLException error) { Logger.getLogger(CheckService.class.getName()).log(Level.SEVERE, null, error); } return VALID_HOSPITAL; }
From source file:com.espertech.esperio.db.SupportDatabaseService.java
public static Object[][] readAll(String tableName) throws SQLException { Connection connection = getConnection(PARTURL, DBUSER, DBPWD); connection.setAutoCommit(true);//from w w w .jav a2 s . c om Statement stmt = connection.createStatement(); String sql = "select * from " + tableName; log.info("Executing sql : " + sql); ResultSet resultSet = stmt.executeQuery(sql); List<Object[]> rows = new ArrayList<Object[]>(); while (resultSet.next()) { List<Object> row = new ArrayList<Object>(); for (int i = 0; i < resultSet.getMetaData().getColumnCount(); i++) { row.add(resultSet.getObject(i + 1)); } rows.add(row.toArray()); } Object[][] arr = new Object[rows.size()][]; for (int i = 0; i < rows.size(); i++) { arr[i] = rows.get(i); } stmt.close(); connection.close(); return arr; }
From source file:com.chiralbehaviors.CoRE.kernel.KernelUtil.java
public static void clear(EntityManager em) throws SQLException { Connection connection = em.unwrap(Connection.class); connection.setAutoCommit(false);//from ww w . j a v a 2 s . c o m alterTriggers(connection, false); ResultSet r = connection.createStatement().executeQuery(KernelUtil.SELECT_TABLE); while (r.next()) { String table = r.getString("name"); String query = String.format("DELETE FROM %s", table); connection.createStatement().execute(query); } r.close(); alterTriggers(connection, true); CACHED_KERNEL.set(null); connection.commit(); }
From source file:com.oracle.tutorial.jdbc.JoinSample.java
public static void getCoffeesBoughtBySupplier(String supplierName, Connection con) throws SQLException { Statement stmt = null;/*from www. j a v a 2 s. c o m*/ String query = "SELECT COFFEES.COF_NAME " + "FROM COFFEES, SUPPLIERS " + "WHERE SUPPLIERS.SUP_NAME LIKE '" + supplierName + "' " + "and SUPPLIERS.SUP_ID = COFFEES.SUP_ID"; try { stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); System.out.println("Coffees bought from " + supplierName + ": "); while (rs.next()) { String coffeeName = rs.getString(1); System.out.println(" " + coffeeName); } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } finally { if (stmt != null) { stmt.close(); } } }
From source file:com.thoughtworks.go.server.datamigration.M001.java
static Migration convertPipelineSelectionsToFilters() { return (cxn) -> { if (!required(cxn)) return; try (Statement s = cxn.createStatement()) { final ResultSet rs = s.executeQuery( "SELECT id, selections, isblacklist FROM pipelineselections WHERE version = 0"); while (rs.next()) { perform(cxn, rs.getLong(ID), rs.getString(SELECTIONS), rs.getBoolean(BLACKLIST)); }/*w w w . j ava 2 s. c o m*/ } }; }
From source file:local.Statistics.LessSellCars.java
/** * @param args the command line arguments *///from w ww. j a v a2 s . c om public static void carrosMenosVendidos() { Graficas_DAO gr = new Graficas_DAO(); ResultSet rs = gr.getgraficaautomas(); try { String nameAuto; int quantitySales; 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 MENOS VENDIDOS", data, true, true, false); ChartFrame frame = new ChartFrame("Autos menos vendidos", chart); frame.pack(); frame.setVisible(true); rs.close(); gr.close(); } catch (SQLException ex) { Logger.getLogger(LessSellCars.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.p6spy.engine.spy.P6TestUtil.java
public static int queryForInt(Connection con, String sql) throws SQLException { Statement stmt = null;//from ww w.ja va2s . c o m ResultSet rs = null; try { stmt = con.createStatement(); rs = stmt.executeQuery(sql); rs.next(); return rs.getInt(1); } finally { if (rs != null) try { rs.close(); } catch (Exception e) { } if (stmt != null) try { stmt.close(); } catch (Exception e) { } } }
From source file:com.senior.g40.service.UserService.java
public static Profile getProfileByUserId(long userId) throws SQLException { Profile pf = null;/*from ww w . j a v a 2 s .co m*/ Connection conn = ConnectionBuilder.getConnection(); String sqlCmd = "SELECT * FROM `profile` WHERE userId = ?;"; PreparedStatement pstm = conn.prepareStatement(sqlCmd); pstm.setLong(1, userId); ResultSet rs = pstm.executeQuery(); if (rs.next()) { pf = new Profile(); setProfile(rs, pf); conn.close(); return pf; } conn.close(); return null; }