List of usage examples for javax.sql.rowset JdbcRowSet getString
String getString(int columnIndex) throws SQLException;
ResultSet
object as a String
in the Java programming language. From source file:Test.java
public static void main(String[] args) throws Exception { String databaseUrl = "jdbc:derby://localhost:1527/contact"; String username = "user"; String password = "password"; RowSetFactory rowSetFactory = null; rowSetFactory = RowSetProvider.newFactory("com.sun.rowset.RowSetFactoryImpl", null); JdbcRowSet rowSet = rowSetFactory.createJdbcRowSet(); rowSet.setUrl(databaseUrl);/*w w w .j a v a 2 s . c o m*/ rowSet.setUsername(username); rowSet.setPassword(password); rowSet.setCommand("SELECT * FROM COLLEAGUES"); rowSet.execute(); while (rowSet.next()) { System.out.println(rowSet.getInt("ID") + " - " + rowSet.getString("FIRSTNAME")); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,name varchar);"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st.executeUpdate("insert into survey (id,name ) values (2,'anotherValue')"); JdbcRowSet jdbcRS = new JdbcRowSetImpl(conn); jdbcRS.setType(ResultSet.TYPE_SCROLL_INSENSITIVE); String sql = "SELECT * FROM survey"; jdbcRS.setCommand(sql);/* w w w. j a v a2s.c o m*/ jdbcRS.execute(); jdbcRS.addRowSetListener(new ExampleListener()); while (jdbcRS.next()) { System.out.println("id=" + jdbcRS.getString(1)); System.out.println("name=" + jdbcRS.getString(2)); } conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,name varchar);"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st.executeUpdate("insert into survey (id,name ) values (2,'anotherValue')"); JdbcRowSet jdbcRS; jdbcRS = new JdbcRowSetImpl(conn); jdbcRS.setType(ResultSet.TYPE_SCROLL_INSENSITIVE); String sql = "SELECT * FROM survey"; jdbcRS.setCommand(sql);// w w w .ja v a 2s.co m jdbcRS.execute(); jdbcRS.addRowSetListener(new ExampleListener()); while (jdbcRS.next()) { // each call to next, generates a cursorMoved event System.out.println("id=" + jdbcRS.getString(1)); System.out.println("name=" + jdbcRS.getString(2)); } conn.close(); }