001: package test;
002:
003: import java.sql.Connection;
004: import java.sql.DriverManager;
005: import java.sql.ResultSet;
006: import java.sql.SQLException;
007: import java.sql.Statement;
008:
009: public class Hsqltest {
010:
011: /**
012: * @param args
013: */
014: public static void main(String[] args) throws SQLException {
015: // TODO Auto-generated method stub
016: try {
017: Class.forName("org.hsqldb.jdbcDriver");
018: //Class.forName("org.gjt.mm.mysql.Driver" );
019: } catch (Exception e) {
020: System.out
021: .println("ERROR: failed to load HSQLDB JDBC driver.");
022: e.printStackTrace();
023: return;
024: }
025:
026: Connection c = DriverManager.getConnection(
027: "jdbc:hsqldb:hsqldata/makumba", "sa", "");
028: //Connection c = DriverManager.getConnection("jdbc:mysql://localhost/makumba", "root", "");
029: c.setAutoCommit(true);
030: c
031: .setTransactionIsolation(java.sql.Connection.TRANSACTION_REPEATABLE_READ);
032:
033: Statement st = c.createStatement();
034: try {
035:
036: //st.executeUpdate("create table adler2(a int, b char(220))");
037: //st.executeUpdate("INSERT INTO adler2 values (1,2)");
038: //st.executeUpdate("CREATE TABLE org_makumba_db_Catalog_(Catalog_ INTEGER,TS_modify_ TIMESTAMP,TS_create_ TIMESTAMP,name_ VARCHAR(255))");
039: //System.out.println(st.executeUpdate("ALTER TABLE TEST_VALIDMDDS_DIVERSITY_ ALTER COLUMN this_ VARBINARY"));
040: //System.out.println(st.executeQuery ("SELECT * FROM org_makumba_db_Catalog_ c LIMIT 1000"));
041:
042: //ResultSet rs = c.getMetaData().getIndexInfo(null,null, "TEST_VALIDMDDS_CHARWITHLENGTH_", false, false);
043:
044: // --- TEST: inser a null value twice
045: //st.executeUpdate("INSERT INTO test_validMdds_Diversity_ (newField_) VALUES ('null')");
046: /*
047: st.executeUpdate("INSERT INTO test_validMdds_Diversity_" +
048: " (Diversity_, ptrFNU_, ptrFN__, ptr_NU_, ptr_N__, PTRF_U_, PTR__U_) VALUES (3, 4, 2, 43, 3, 4, 3)");
049: */
050:
051: /* ResultSet rs1 = st.executeQuery("SELECT * FROM test_validMdds_Diversity_");
052: while (rs1.next()) {
053: System.out.println("["+rs1.getString("cHar_")+
054: "|"+rs1.getString("Diversity_")+"|"+
055: rs1.getString("ptrFNU_")+"]\n");
056: }
057: */
058:
059: /* ResultSet rs = c.getMetaData().getIndexInfo(null,null, "test_validMdds_Diversity_".toUpperCase(),false, false);
060:
061: while (rs.next()) {
062: String iname = rs.getString("INDEX_NAME");
063: System.out.println(" ---> ["+iname+"] ");
064: boolean non_unique = rs.getBoolean("NON_UNIQUE");
065:
066: }
067: */
068:
069: ResultSet rs2;
070: //SELECT avg(r.r_) as av, sum(r.r_) as su FROM test.validMdds.Real_ r");
071: //rs2 = st.executeQuery("SELECT avg(r.r_) AS av, sum(r.r_) AS su FROM TEST_VALIDMDDS_REAL_ r");
072: //st.executeUpdate("INSERT INTO TEST_VALIDMDDS_REAL_ (real_, r_) VALUES (3, 3)");
073: //rs2 = st.executeQuery("SELECT * FROM TEST_VALIDMDDS_REAL_ r");
074:
075: //--- test with REAL ---
076: //rs2 = st.executeQuery("SELECT avg(r.r_) as av, sum(r.r_) as su FROM TEST_VALIDMDDS_REAL_ r");
077: //--- test with INT ---
078: //rs2 = st.executeQuery("SELECT * FROM TEST_VALIDMDDS_INT_ i");
079:
080: //for (int vari=0;vari < 6; vari++) {
081: // st.executeUpdate("INSERT INTO TEST_VALIDMDDS_INT_ (int_, i_) VALUES ("+vari+", "+vari+")");
082: //}
083: rs2 = st
084: .executeQuery("SELECT avg(0.0+i.i_) as av, sum(i.i_) as su FROM TEST_VALIDMDDS_INT_ i");
085:
086: while (rs2.next()) {
087: //String stuff = rs2.getString("i_");
088: //System.out.println(" ---> ["+stuff+"]");
089:
090: String sum = rs2.getString("su");
091: String avg = rs2.getString("av");
092: System.out.println(" ---> sum[" + sum + "] avg[" + avg
093: + "] ");
094: }
095:
096: System.out.println(".end.");
097:
098: //r=real ;The real number (Double precision)
099:
100: } finally {
101: st.executeUpdate("SHUTDOWN"); //comment if you use mySQL, needed with Hsqldb
102: c.close();
103: }
104: }
105:
106: }
|