List of usage examples for javax.sql.rowset WebRowSet execute
public void execute(Connection conn) throws SQLException;
CachedRowSet
object with data, using the given connection to produce the result set from which the data will be read. From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st = conn.createStatement();/*from w ww . j a v a 2 s . com*/ String query = "select * from survey where 1 = 0"; WebRowSet webRS = new WebRowSetImpl(); webRS.setCommand(query); webRS.execute(conn); // convert xml to a String object StringWriter sw = new StringWriter(); webRS.writeXml(sw); System.out.println(sw.toString()); st.close(); 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("create view surveyView as (select * from survey);"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st.executeUpdate("insert into survey (id,name ) values (2,'anotherValue')"); String sqlQuery = "SELECT * FROM survey"; WebRowSet webRS = new WebRowSetImpl(); webRS.setCommand(sqlQuery);/*from www. j av a 2 s . c om*/ webRS.execute(conn); // create RowSetMetaData object RowSetMetaData rsMD = (RowSetMetaData) webRS.getMetaData(); System.out.println("rsMD=" + rsMD); if (rsMD == null) { System.out.println("vendor does not support RowSetMetaData"); } else { int columnCount = rsMD.getColumnCount(); System.out.println("columnCount=" + columnCount); } 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')"); Statement stmt = conn.createStatement(); String sqlQuery = "SELECT * FROM survey WHERE id='1'"; WebRowSet webRS = new WebRowSetImpl(); webRS.setCommand(sqlQuery);//from ww w . j a v a 2 s. c om webRS.execute(conn); File file = new File("1.xml"); FileWriter fw = new FileWriter(file); System.out.println("Writing db data to file " + file.getAbsolutePath()); webRS.writeXml(fw); StringWriter sw = new StringWriter(); webRS.writeXml(sw); System.out.println(sw.toString()); fw.flush(); fw.close(); stmt.close(); 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')"); WebRowSet webRS; ResultSet rs = null;// w ww .j a va 2 s .c o m Statement stmt = null; stmt = conn.createStatement(); webRS = null; String sqlQuery = "SELECT * FROM survey WHERE id='1'"; webRS = new WebRowSetImpl(); webRS.setCommand(sqlQuery); webRS.execute(conn); FileWriter fw = null; File file = new File("1.xml"); fw = new FileWriter(file); System.out.println("Writing db data to file " + file.getAbsolutePath()); webRS.writeXml(fw); // convert xml to a String object StringWriter sw = new StringWriter(); webRS.writeXml(sw); System.out.println("=============="); System.out.println(sw.toString()); System.out.println("=============="); fw.flush(); fw.close(); rs.close(); stmt.close(); conn.close(); }