1 42 43 import java.io.*; 44 import java.sql.*; 45 import java.util.*; 46 47 import org.jdom.*; 48 import org.jdom.output.*; 49 50 import org.jdom.contrib.input.ResultSetBuilder; 51 52 public class ResultSetBuilderDemo { 53 54 56 static final String PREP = 57 "create table rsbd ( " + 58 "id int PRIMARY KEY, " + 59 "name varchar(255) NOT NULL, " + 60 "home_url varchar(255) NULL, " + 61 "contact_email varchar(255) NULL, " + 62 "contact_phone varchar(255) NULL, " + 63 "location varchar(255) NULL, " + 64 "comments long varchar NULL, " + 65 "free_hosting boolean NULL, " + 66 "state_flag tinyint NOT NULL, " + "submitter_email varchar(255) NULL, " + "created_time timestamp NOT NULL, " + 69 "modified_time timestamp NOT NULL " + 70 ")"; 71 72 static final String FILL = 73 "insert into rsbd (id, name, home_url, contact_email, " + 74 "contact_phone, comments, free_hosting, state_flag, created_time, " + 75 "modified_time) values (2, 'sphere', null, 'info@sphere', " + 76 "'1234', 'cool', true, 10, " + 77 "{ts '1999-02-09 20:11:11.123455'}, " + 78 "{ts '1999-03-21 22:11:11.123455'})"; 79 80 public static void main(String [] args) throws Exception { 81 Class.forName("COM.cloudscape.core.JDBCDriver"); 83 Connection con = 84 DriverManager.getConnection("jdbc:cloudscape:rsbd;create=true"); 85 86 Statement prep = con.createStatement(); 88 prep.executeUpdate(PREP); 89 90 Statement fill = con.createStatement(); 91 fill.executeUpdate(FILL); 92 93 Namespace ns = Namespace.getNamespace("xhtml", "http://w3.org/etc"); 94 95 Statement stmt = con.createStatement(); 96 ResultSet rs = stmt.executeQuery( 97 "select id, name, home_url || contact_phone from rsbd"); 98 ResultSetBuilder builder = new ResultSetBuilder(rs); 99 builder.setAsElement(3, "num3"); 100 builder.setAsAttribute("created_time", "ctime"); 107 Document doc = builder.build(); 108 XMLOutputter outputter = new XMLOutputter(); 109 outputter.output(doc, System.out); 110 } 111 } 112 | Popular Tags |