List of usage examples for org.springframework.jdbc.support.rowset SqlRowSet next
boolean next() throws InvalidResultSetAccessException;
From source file:flywayspike.Main.java
/** * Runs the sample.//from w w w. jav a 2 s. co m * * @param args None supported. */ public static void main(String[] args) throws Exception { DataSource dataSource = new SimpleDriverDataSource(new org.hsqldb.jdbcDriver(), "jdbc:hsqldb:file:db/flyway_sample;shutdown=true", "SA", ""); Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.setLocations("flywayspike.migration", "abcd"); flyway.clean(); System.out.println("Started Migration"); flyway.migrate(); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); List<Map<String, Object>> results = jdbcTemplate.queryForList("select name from test_user"); for (Map<String, Object> result : results) { System.out.println("Name: " + result.get("NAME")); } SqlRowSet rowSet = jdbcTemplate.queryForRowSet("select * from schema_version"); while (rowSet.next()) { System.out.print(rowSet.getObject(1)); System.out.println(" " + rowSet.getObject(2)); } }
From source file:p1.PointDAO.java
public static ArrayList<Point> getPoints() { SqlRowSet srs = jt.queryForRowSet("select * from point"); int x = 0, y = 0, id = 0; while (srs.next()) { id = srs.getInt("id"); x = srs.getInt("x"); y = srs.getInt("y"); al.add(new Point(id, x, y)); }//from w ww . java 2 s .c om return al; }
From source file:p1.PointDAO.java
public static Point getPoint(Point p) { SqlRowSet srs = jt.queryForRowSet("select * from point where id=" + p.getId()); int x = 0, y = 0, id = 0; Point p1 = null;//from w w w . j a va2 s . com while (srs.next()) { x = srs.getInt("x"); y = srs.getInt("y"); p1 = new Point(p.getId(), x, y); } return p1; }
From source file:com.esa.infocontrol.data.jdbc.BaseDataJDBC.java
public static DataArrayWrapper getList(DataSource dataSource, String query, MapSqlParameterSource params) { LOG.debug("QUERY: {}", query); if (params != null) { LOG.debug("\tPARAMETERS: {}", params.getValues().toString()); }/* w ww. j a v a 2 s . c o m*/ NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); SqlRowSet rs = jdbcTemplate.queryForRowSet(query, params); SqlRowSetMetaData md = rs.getMetaData(); LOG.debug("\tCOLUMNS: {}", Arrays.toString(md.getColumnNames())); List<DataRow> dataList = new ArrayList<>(); ColumnMetaData[] columnMetaData = new ColumnMetaData[md.getColumnCount()]; for (int i = 1; i <= md.getColumnCount(); ++i) { columnMetaData[i - 1] = new ColumnMetaData(md.getColumnLabel(i), md.getColumnType(i)); } while (rs.next()) { DataRow row = new DataRow(md.getColumnCount()); for (int i = 1; i <= md.getColumnCount(); ++i) { row.add(rs.getString(i)); } dataList.add(row); } return new DataArrayWrapper(dataList, columnMetaData); }
From source file:org.owasp.proxy.http.dao.JdbcMessageDAOTest.java
private static void dump(String sql) { logger.fine("\n" + sql); SqlRowSet rs = dao.getJdbcTemplate().queryForRowSet(sql); try {/*from w w w . j a va2 s . co m*/ SqlRowSetMetaData rsmd = rs.getMetaData(); int c = rsmd.getColumnCount(); StringBuffer buff = new StringBuffer(); for (int i = 1; i <= c; i++) { buff.append(rsmd.getColumnLabel(i)); buff.append(i == c ? "\n" : "\t"); } logger.fine(buff.toString()); buff.delete(0, buff.length()); while (rs.next()) { for (int i = 1; i <= c; i++) { buff.append(rs.getObject(i)); buff.append(i == c ? "\n" : "\t"); } logger.fine(buff.toString()); buff.delete(0, buff.length()); } logger.fine("================\n\n"); } catch (Exception e) { e.printStackTrace(); } }
From source file:transaction.script.ProjectTrScript.java
/** * @param template/*from ww w .j ava 2 s. co m*/ * @param query * @param conditionsMapList * @return * @throws SQLException */ public static boolean query(JdbcTemplate template, String query, List<Map<String, Object>> conditionsMapList) throws SQLException { logger.info("Query to execute is: " + query); SqlRowSet set = template.queryForRowSet(query); boolean result = true; SqlRowSetMetaData mdata = set.getMetaData(); int columnAmount = mdata.getColumnCount(); logger.info("Columns: " + columnAmount); logger.info("Map size: " + conditionsMapList.size()); //TODO if (set.first()) { set.last(); int rowNum = set.getRow(); result = (rowNum == conditionsMapList.size()); set.beforeFirst(); } else { if (!conditionsMapList.get(0).isEmpty()) { result = false; } } logger.info("Two maps comparison result is " + result); if (result) { while (set.next()) { int rowNum = set.getRow(); Map<String, Object> map = conditionsMapList.get(rowNum - 1); for (int i = 1; i <= columnAmount; i++) { result &= map.containsKey(mdata.getColumnName(i)) && map.get(mdata.getColumnName(i)).toString().equals(set.getObject(i).toString()); } } } return result; }
From source file:edu.pitt.sis.infsci2730.finalProject.service.TransactionService.java
public int GetTranactionTotalAmount(final String id) throws SQLException { SqlRowSet s = TransactionDao.GetTranactionTotalAmount(id); if (s.next()) { return s.getInt(1); }/* w w w. j ava 2 s .c om*/ return -1; }
From source file:CRM.repository.UsersDAO.java
public int getUserCount() { String sql = "SELECT COUNT(username) AS rowcount FROM users"; SqlRowSet rs = template.queryForRowSet(sql); if (rs.next()) { return rs.getInt("rowcount"); }//from www.ja v a 2 s.c o m return 1; }
From source file:lydichris.smashbracket.persistence.UserPersistence.java
public boolean checkEmailExists(String email) { String SQL = "select count(username) from users where email = ?"; SqlRowSet result = jdbcTemplateObject.queryForRowSet(SQL, email); if (result.next()) { return result.getInt("count(username)") > 0; } else {/*from w w w. jav a 2 s.c o m*/ return false; } }
From source file:lydichris.smashbracket.persistence.UserPersistence.java
public boolean checkUsernameExists(String username) { String SQL = "select count(username) from users where username = ?"; SqlRowSet result = jdbcTemplateObject.queryForRowSet(SQL, username); if (result.next()) { return result.getInt("count(username)") > 0; } else {/*w w w . j a v a2 s.co m*/ return false; } }