List of usage examples for java.sql ResultSet isLast
boolean isLast() throws SQLException;
ResultSet
object. From source file:org.silverpeas.migration.jcr.version.VersioningMigrator.java
private List<ComponentDocumentMigrator> buildComponentMigrators() throws SQLException { List<ComponentDocumentMigrator> result = new ArrayList<ComponentDocumentMigrator>(500); Statement stmt = null;/* w w w . j a v a 2 s . c om*/ ResultSet rs = null; getConsole().printMessage("All components to be migrated : "); try { stmt = getConnection().createStatement(); rs = stmt.executeQuery(SELECT_COMPONENTS); while (rs.next()) { result.add(new ComponentDocumentMigrator(rs.getString("instanceid"), service, getConsole())); getConsole().printMessage(rs.getString("instanceid")); if (!rs.isLast()) { getConsole().printMessage(", "); } } getConsole().printMessage("*************************************************************"); return result; } catch (SQLException sqlex) { throw sqlex; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); } }
From source file:org.silverpeas.migration.jcr.attachment.AttachmentMigrator.java
protected List<ComponentAttachmentMigrator> buildComponentMigrators() throws SQLException { List<ComponentAttachmentMigrator> result = new ArrayList<ComponentAttachmentMigrator>(500); Statement stmt = null;/*from www. jav a2 s .co m*/ ResultSet rs = null; getConsole().printMessage("All components to be migrated : "); try { stmt = getConnection().createStatement(); rs = stmt.executeQuery(SELECT_COMPONENTS); while (rs.next()) { result.add(new ComponentAttachmentMigrator(rs.getString("instanceid"), service, getConsole())); getConsole().printMessage(rs.getString("instanceid")); if (!rs.isLast()) { getConsole().printMessage(", "); } } getConsole().printMessage("*************************************************************"); return result; } catch (SQLException sqlex) { throw sqlex; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); } }
From source file:com.imagelake.control.PaymentPreferenceDAOImp.java
@Override public String getJSONPaymentPreferances(int state) { StringBuffer sb = null;/*from www . j a v a 2 s. c om*/ int dataCount = 0; int pages = 0; PaymentAccountDAOImp pad = new PaymentAccountDAOImp(); try { sb = new StringBuffer("{'prefarence':{"); sb.append("'pages':["); String sql = "SELECT * FROM payment_preferences WHERE state=?"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ps.setInt(1, state); ResultSet rs = ps.executeQuery(); System.out.println("total:" + getResultSetCount(rs)); while (rs.next()) { if (dataCount % 10 == 0) { pages++; if (rs.isLast()) { sb.append("{'id':'" + rs.getString(1) + "','userid':'" + rs.getString(2) + "','reqdate':'" + rs.getString(3) + "','acctype':'" + pad.getPaymetAccountName(rs.getInt(5)) + "','amount':'" + rs.getDouble(7) + "','state':'" + rs.getInt(8) + "','email':'" + rs.getString(9) + "','no':'" + pages + "'}"); } else { sb.append("{'id':'" + rs.getString(1) + "','userid':'" + rs.getString(2) + "','reqdate':'" + rs.getString(3) + "','acctype':'" + pad.getPaymetAccountName(rs.getInt(5)) + "','amount':'" + rs.getDouble(7) + "','state':'" + rs.getInt(8) + "','email':'" + rs.getString(9) + "','no':'" + pages + "'},"); } } if (dataCount % 10 != 0) { if (rs.isLast()) { sb.append("{'id':'" + rs.getString(1) + "','userid':'" + rs.getString(2) + "','reqdate':'" + rs.getString(3) + "','acctype':'" + pad.getPaymetAccountName(rs.getInt(5)) + "','amount':'" + rs.getDouble(7) + "','state':'" + rs.getInt(8) + "','email':'" + rs.getString(9) + "','no':'" + pages + "'}"); } else { sb.append("{'id':'" + rs.getString(1) + "','userid':'" + rs.getString(2) + "','reqdate':'" + rs.getString(3) + "','acctype':'" + pad.getPaymetAccountName(rs.getInt(5)) + "','amount':'" + rs.getDouble(7) + "','state':'" + rs.getInt(8) + "','email':'" + rs.getString(9) + "','no':'" + pages + "'},"); } } System.out.println("id:" + rs.getInt(1)); System.out.println(dataCount + "||" + dataCount % 10); System.out.println("pages" + pages); dataCount++; } sb.append("],"); sb.append("'leng':'" + pages + "',"); sb.append("}"); sb.append("}"); } catch (Exception e) { e.printStackTrace(); } return sb.toString(); }
From source file:nl.b3p.viewer.ViewerIntegrationTest.java
/** * test if the database has the right metadata version. * * @throws SQLException if something goes wrong executing the query * @throws ClassNotFoundException if the postgres driver cannot be found. */// w ww . j av a 2s . c o m @Test public void testMetadataVersion() throws SQLException, ClassNotFoundException { // get 'database_version' from table metadata and check that is has the value of 'n' Connection connection = DriverManager.getConnection(databaseprop.getProperty("testdb.url"), databaseprop.getProperty("testdb.username"), databaseprop.getProperty("testdb.password")); ResultSet rs = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY) .executeQuery("SELECT config_value FROM metadata WHERE config_key = 'database_version'"); String actual_config_value = "-1"; while (rs.next()) { actual_config_value = rs.getString("config_value"); } assertThat("There is only one 'database_version' record (first and last should be same record).", rs.isLast(), equalTo(rs.isFirst())); rs.close(); connection.close(); assertEquals("The database version should be the same.", DatabaseSynchronizer.getUpdateNumber(), actual_config_value); }
From source file:org.apache.cocoon.taglib.core.ForEachSupport.java
protected ForEachIterator toForEachIterator(ResultSet rs) throws SAXException { // local adapter class ResultSetAdapter implements ForEachIterator { private ResultSet rs; public ResultSetAdapter(ResultSet rs) { this.rs = rs; }/*from ww w .j a va 2 s . c o m*/ public boolean hasNext() throws SAXException { try { return !(rs.isLast()); // dependent on JDBC 2.0 } catch (java.sql.SQLException ex) { throw new SAXException(ex.getMessage()); } } public Object next() throws SAXException { try { rs.next(); return rs; } catch (java.sql.SQLException ex) { throw new SAXException(ex.getMessage()); } } } return new ResultSetAdapter(rs); }
From source file:org.apache.jackrabbit.oak.plugins.document.rdb.RDBExport.java
private static void dumpJDBC(String url, String user, String pw, String table, String query, Format format, PrintStream out, List<String> fieldNames, RDBDocumentSerializer ser) throws SQLException { String driver = RDBJDBCTools.driverForDBType(RDBJDBCTools.jdbctype(url)); try {// w ww .ja v a2 s . c o m Class.forName(driver); } catch (ClassNotFoundException ex) { System.err.println( RDBExport.class.getName() + ":attempt to load class " + driver + " failed:" + ex.getMessage()); } Connection c = DriverManager.getConnection(url, user, pw); c.setReadOnly(true); Statement stmt = c.createStatement(); String sql = "select ID, MODIFIED, MODCOUNT, CMODCOUNT, HASBINARY, DELETEDONCE, DATA, BDATA from " + table; if (query != null) { sql += " where " + query; } sql += " order by id"; ResultSet rs = stmt.executeQuery(sql); if (format == Format.JSONARRAY) { out.println("["); } else if (format == Format.CSV) { out.println(dumpFieldNames(fieldNames)); } boolean needComma = format == Format.JSONARRAY; ResultSetMetaData rsm = null; boolean idIsAscii = true; while (rs.next()) { if (rsm == null) { rsm = rs.getMetaData(); idIsAscii = !isBinaryType(rsm.getColumnType(1)); } String id = idIsAscii ? rs.getString("ID") : new String(rs.getBytes("ID"), UTF8); long modified = rs.getLong("MODIFIED"); long modcount = rs.getLong("MODCOUNT"); long cmodcount = rs.getLong("CMODCOUNT"); long hasBinary = rs.getLong("HASBINARY"); long deletedOnce = rs.getLong("DELETEDONCE"); String data = rs.getString("DATA"); byte[] bdata = rs.getBytes("BDATA"); RDBRow row = new RDBRow(id, hasBinary == 1, deletedOnce == 1, modified, modcount, cmodcount, data, bdata); StringBuilder fulljson = dumpRow(ser, id, row); if (format == Format.CSV) { out.println(asCSV(fieldNames, fulljson)); } else { fulljson = asJSON(fieldNames, fulljson); if (format == Format.JSONARRAY && needComma && !rs.isLast()) { fulljson.append(","); } out.println(fulljson); needComma = true; } } if (format == Format.JSONARRAY) { out.println("]"); } out.close(); rs.close(); stmt.close(); c.close(); }
From source file:com.darkenedsky.reddit.traders.RedditTraders.java
/** * Check if two users are banned, using the appropriate method defined in * the checkBan parameter/*from w ww . jav a 2 s .c o m*/ * * @param author * first user to check * @param tradeWith * second user to check * @param subreddit * subreddit we are checking in (if not ALL) * @param checkBan * checkban mode on the subreddit * @return true if either user is banned * @throws Exception */ public boolean checkBans(String author, String tradeWith, String subreddit, int checkBan) throws Exception { // checking is turned off switch (checkBan) { case 1: return this.isBanned(author, tradeWith, subreddit); case 2: PreparedStatement ps = config.getJDBC().prepareStatement("select subreddit from subreddits;"); ResultSet subs = ps.executeQuery(); if (subs.first()) { while (true) { if (isBanned(author, tradeWith, subs.getString("subreddit"))) { subs.close(); return true; } if (subs.isLast()) { break; } subs.next(); } } subs.close(); return false; // checking is turned off default: return false; } }
From source file:it.unibas.spicy.persistence.json.ExportJsonInstances.java
public void createJsonDocument(String tableName, String schema, INode tableNode, String folderPath, Statement statement) throws SQLException, IOException { BufferedWriter bw = null;//from w w w . java2s . c om ResultSet instancesSet = null; try { File file = new File(folderPath + File.separator + tableName + ".json"); FileWriter fw = new FileWriter(file.getAbsoluteFile()); bw = new BufferedWriter(fw); if (!file.exists()) { file.createNewFile(); } instancesSet = statement.executeQuery( "SELECT row_to_json(\"" + tableName + "\") FROM " + schema + ".\"" + tableName + "\";"); //check to see if the result set is empty if (instancesSet.isBeforeFirst()) { bw.write("["); bw.newLine(); while (instancesSet.next()) { bw.write(instancesSet.getString(1)); //if it is not the last result if (!instancesSet.isLast()) { bw.write(","); } bw.newLine(); } bw.write("]"); } //alternative for one-row json /*instancesSet = statement.executeQuery("SELECT array_to_json(array_agg("+"\""+tableName+"\")) FROM "+schema+"\""+tableName+"\";"); while (instancesSet.next() && instancesSet.getString(1)!=null){ bw.write(instancesSet.getString(1)); } }*/ } finally { bw.close(); instancesSet.close(); } }
From source file:de.klemp.middleware.controller.Controller.java
/** * This method returns the names of the devices which are registered. * /*from www. j a v a 2s . c o m*/ * @param component * 1 or 2 * @param classes * class to get the names of * @return a String off all names from a class */ public static synchronized String getNames(int component, String classes) { String names = ""; ResultSet result = null; if (!classes.equals("VLCPlayerIntern")) { createDBConnection(); try { if (component == 1) { PreparedStatement st = conn.prepareStatement("select name from \"InputDevices\"where class=?;"); st.setString(1, classes); result = st.executeQuery(); } if (component == 2) { PreparedStatement st = conn .prepareStatement("select topic from \"OutputDevices\" where class=?;"); st.setString(1, classes); result = st.executeQuery(); } while (result.next()) { String name = result.getString(1); if (!result.isLast()) { names = names + "" + name + ","; } else { names = names + name; } } } catch (SQLException e) { logger.error("SQL Exception in Method getNames", e); } } else { names = "----------------"; } closeDBConnection(); return names; }
From source file:org.msec.LogQuery.java
public void showRecords() throws SQLException { String tableName = tableNamePrefix + dayFormatter.format(new Date()); DatabaseMetaData md = conn.getMetaData(); ResultSet rs = md.getTables(null, null, tableName, null); if (rs.next()) { System.out.println("table " + tableName + " exist"); } else {//from w w w. j a v a 2 s .c o m System.out.println("table " + tableName + " not exist"); return; } String columnList = ""; rs = md.getColumns(null, null, tableName, null); while (rs.next()) { columnList += rs.getString("COLUMN_NAME"); if (!rs.isLast()) columnList += ","; } System.out.println(columnList); String sql = "select * from " + tableName; //SQL rs = stmt.executeQuery(sql);// System.out.println("ip" + "\t" + "level" + "\t" + "rpcname" + "\t\t" + "time" + "\t" + "content"); while (rs.next()) { System.out.print(rs.getString(1) + "\t"); System.out.print(rs.getString(2) + "\t"); System.out.print(rs.getString(3) + "\t"); System.out.print(rs.getString(4) + "\t"); System.out.print(rs.getString(5) + "\t"); System.out.println(); } rs.close(); }