1 30 package com.genimen.djeneric.jdbc; 31 32 import java.io.PrintWriter ; 33 import java.sql.Connection ; 34 import java.sql.DatabaseMetaData ; 35 import java.sql.DriverManager ; 36 import java.sql.ResultSet ; 37 import java.sql.ResultSetMetaData ; 38 import java.sql.Statement ; 39 40 import org.hsqldb.util.ShutdownServer; 41 42 import com.genimen.djeneric.util.DjLogger; 43 44 48 49 public class Test 50 { 51 public Test() 52 { 53 } 54 55 public static void main(String [] args) 56 { 57 try 58 { 59 DriverManager.setLogWriter(new PrintWriter (System.out)); 60 new DbRunner("C:/sjared/products/eclipse/workspace/Djeneric/db/gdp2"); 61 } 64 catch (Exception e) 65 { 66 67 } 68 try 69 { 70 Test test1 = new Test(); 72 for (int i = 0; i < 1; i++) 73 test1.run(); 74 System.out.println("==============================DONE================================="); 75 } 76 catch (Exception ex) 77 { 78 System.err.println("exception thrown during test"); 79 DjLogger.log(ex); 80 } 81 } 83 84 void run() throws Exception 85 { 86 Class.forName("com.genimen.djeneric.jdbc.DjDriver"); 87 String NAME = "name=sa@hypersonic;"; 88 String LOC = "location=Polymorph RDBMS;"; 89 String DRV = "driver=org.hsqldb.jdbcDriver;"; 90 String URL = "url=jdbc:hsqldb:hsql://localhost:9876;"; 91 String USR = "user=sa;"; 92 String PWD = "password=;"; 93 Connection c = DriverManager.getConnection("jdbc:djeneric:" + NAME + LOC + DRV + URL + USR + PWD); 95 96 DatabaseMetaData dbm = c.getMetaData(); 97 98 ResultSet tables = dbm.getTables(null, null, "", new String []{"TABLE"}); 99 ResultSetMetaData tablesMeta = tables.getMetaData(); 100 101 while (tables.next()) 102 { 103 System.out.println("new table"); 104 for (int tc = 1; tc <= tablesMeta.getColumnCount(); tc++) 105 { 106 System.out.print(tables.getString(tc)); 107 System.out.print(" "); 108 } 109 System.out.println("-- table data follows --"); 110 111 Statement s = c.createStatement(); 112 ResultSet rs = s.executeQuery("select * from " + tables.getString("TABLE_NAME")); 113 System.out.println(rs); 114 rs.close(); 115 s.close(); 116 } 117 tables.close(); 118 c.close(); 119 131 } 132 } 133 134 class DbRunner extends Thread 135 { 136 String _dbloc; 137 boolean _isRunning = false; 138 static DbRunner _runningThread = null; 139 140 public DbRunner(String dbloc) 141 { 142 _dbloc = dbloc; 143 setDaemon(false); 144 start(); 145 try 146 { 147 Thread.sleep(3000); 148 } 149 catch (Exception ee) 150 { 151 } 152 } 153 154 public void run() 155 { 156 _runningThread = this; 157 _isRunning = true; 158 org.hsqldb.Server.main(new String []{"-no_system_exit", "true", "-port", "9876", "-database", _dbloc}); 159 _isRunning = false; 160 } 161 162 public boolean isRunning() 163 { 164 return _isRunning; 165 } 166 167 public void quit() 168 { 169 ShutdownServer.main(new String []{"-user", "sa", "-password", "", "-port", "9876", "-shutdownarg", "COMPACT"}); 170 while (isRunning()) 171 { 172 try 173 { 174 Thread.sleep(500); 175 } 176 catch (Exception e) 177 { 178 } 179 } 180 } 181 } | Popular Tags |