01: /*
02: * Created on Oct 11, 2004
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package org.hammurapi.inspectors.metrics;
08:
09: import java.sql.Connection;
10: import java.sql.DriverManager;
11: import java.sql.ResultSet;
12: import java.sql.Statement;
13:
14: /**
15: * @author 111001082
16: *
17: * TODO To change the template for this generated type comment go to
18: * Window - Preferences - Java - Code Style - Code Templates
19: */
20: public class HsqlTest {
21:
22: public static void main(String[] args) {
23: try {
24: Class.forName("org.hsqldb.jdbcDriver");
25: // Connection c = DriverManager.getConnection("jdbc:hsqldb:file:D:/anwend/java/hsqldb/data/myjobdb", "sa", "");
26: Connection c = DriverManager.getConnection(
27: "jdbc:hsqldb:hsql://localhost/job", "sa", "");
28: Statement stmt = c.createStatement();
29:
30: String sqlQuery = "CREATE CACHED TABLE SQL_STRING_LITERALS (LITERAL VARCHAR(250), SOURCE VARCHAR(250), LINE INTEGER, COL INTEGER, CLASS_NAME VARCHAR(250), CLASS_FCN VARCHAR(250));";
31: ResultSet rs = stmt.executeQuery(sqlQuery);
32: sqlQuery = "CREATE INDEX IX_SQL_STRING_LITERALS ON SQL_STRING_LITERALS (LITERAL, SOURCE, LINE, COL);";
33: rs = stmt.executeQuery(sqlQuery);
34: sqlQuery = "CREATE CACHED TABLE VAR_DEF_LITERALS (VAR_NAME VARCHAR(250), VAR_VALUE VARCHAR(250), SOURCE VARCHAR(250), LINE INTEGER, COL INTEGER, CLASS_NAME VARCHAR(250), CLASS_FCN VARCHAR(250));";
35: rs = stmt.executeQuery(sqlQuery);
36: sqlQuery = "CREATE INDEX IX_VAR_DEF_LITERALS ON VAR_DEF_LITERALS (VAR_NAME, VAR_VALUE, SOURCE, LINE, COL);";
37: rs = stmt.executeQuery(sqlQuery);
38:
39: /*
40: String sqlQuery = "CREATE TABLE cdShop (cdNr INTEGER, cdArtist CHAR(20),cdTitle CHAR(20));";
41: ResultSet rs = stmt.executeQuery(sqlQuery);
42:
43: sqlQuery = "INSERT INTO cdShop VALUES (1,'Groeni','Mensch')";
44: rs = stmt.executeQuery(sqlQuery);
45: sqlQuery = "INSERT INTO cdShop VALUES (2,'Sting','Fields of Gold')";
46: rs = stmt.executeQuery(sqlQuery);
47: sqlQuery = "INSERT INTO cdShop VALUES (3,'Bach','Pluratorium')";
48: rs = stmt.executeQuery(sqlQuery);
49:
50: sqlQuery = "UPDATE cdShop SET cdTitle='W-Oratorium' WHERE cdNr=1";
51: rs = stmt.executeQuery(sqlQuery);
52:
53: sqlQuery = "SELECT * FROM cdShop";
54: rs = stmt.executeQuery(sqlQuery);
55: System.out.println("\n\n\nCD Shop DB\n=============\n");
56: int counter = 0;
57: while (rs.next()) {
58: System.out.println(counter++ +".Datensatz:");
59: int cdNr = rs.getInt("cdNr");
60: System.out.println("\t[cdNr ->" + cdNr + "]");
61: String cdArtist = rs.getString("cdArtist");
62: System.out.println("\t[cdArtist ->" + cdArtist + "]");
63: String cdTitle = rs.getString("cdTitle");
64: System.out.println("\t[cdTitle ->" + cdTitle + "]\n");
65:
66: sqlQuery = "DROP TABLE cdShop ;";
67: rs = stmt.executeQuery(sqlQuery);
68: }
69: */
70: c.close();
71:
72: System.out.println("Done ");
73: } catch (Exception e) {
74: // TODO Auto-generated catch block
75: e.printStackTrace();
76: }
77:
78: }
79:
80: }
|