problem with timestamps in HSQL



Hey All,

I am having problems trying to insert a TIMESTAMP value into a simple
HSQL database, see code below. The print statement indicates the
formatting of the timestamp looks reasonable, but I can never get past
the "Wrong data type" exception. I've tried various formatting of the
timestamp string to no avail. Does anyone know what's wrong?

std out:
----------------------------------------------------------------------------
INSERT INTO DATA VALUES('2005-06-24
22:18:53.109000000',48.89959329052301,64.86097067315892)
--------------------------
java.sql.SQLException: Wrong data type: type: TIMESTAMP (93) expected:
REAL value: 2005-06-24 22:18:53.109

code:
----------------------------------------------------------------------------

public final class HSQLTest {

private Connection conn;
//private final SimpleDateFormat formatter = new
SimpleDateFormat("yyyy-MM-dd hh:mm:ss.0");

public HSQLTest() throws SQLException, InstantiationException,
IllegalAccessException, ClassNotFoundException {
Class.forName("org.hsqldb.jdbcDriver").newInstance();
conn = DriverManager.getConnection("jdbc:hsqldb:mem:aname", "sa",
"");
final Statement stmt = conn.createStatement();
stmt.executeUpdate("CREATE TABLE DATA(TIME TIMESTAMP, VOLTAGE
FLOAT, TEMP FLOAT)");
stmt.close();
}

public void populateTable() {

final Calendar cal = new GregorianCalendar();
new Thread() {

public void run() {

while (true) {
try {
final Statement stmt = conn.createStatement();
final String t =
HsqlDateTime.getTimestampString(new
Timestamp(System.currentTimeMillis()), cal);
final String insertSQL = "INSERT INTO DATA
VALUES('" + t + "'," + ((Math.random() * 5.0) + 48.0) + "," +
((Math.random() * 5.0) + 60.0) + ")";
System.out.println(insertSQL);
stmt.executeUpdate(insertSQL);

final ResultSet rs = stmt.executeQuery("SELECT
* FROM DATA");

System.out.println("--------------------------");
while (rs.next()) {
System.out.println(rs.getDate(1) + "," +
rs.getFloat(1) + "," + rs.getFloat(2));
}

} catch (Exception ex) {
ex.printStackTrace();
}

try {
sleep(1000);
} catch (InterruptedException e) {
}
}
}

}.start();

}

public static void main(String[] args) throws Exception {
new HSQLTest().populateTable();
}
}

.



Relevant Pages

  • Re: Entering a TimeStamp value into DB2
    ... I went to google and searched for "db2 timestamp" and this ... If formatting the date and time data is a major consideration for your ... These facilities are not available for TIMESTAMP columns. ... correctly format the 'TimeStamp' value in my script so that the ...
    (perl.dbi.users)
  • Windows Scripting - Timestamp, files, need help. :)
    ... I need to write a script in vbscript (I want to use ... Gets the Highest (most recent timestamp) and compares it to the current ... and formatting it YYYYMMDDHHMM ... formatting each item in the array into the format YYYYMMDDHHMM ...
    (microsoft.public.scripting.vbscript)
  • Re: Ruby "Speedup" hints?
    ... heavy stuff to convert from to timestamp. ... Once we did a log merger and we ordered the entries by time. ... a lot of processing time by storing the timestamps in the logs along ... (They were removed afterwards during formatting.) ...
    (comp.lang.ruby)
  • Re: Php Date-Formatting Help
    ... >> I have a date value that I pull from a .csv file. ... >> formatting to work ... > Returns a string formatted according to the given format string using the ... > given integer timestamp or the current local time if no timestamp is ...
    (comp.lang.php)
  • Re: problem with timestamps in HSQL
    ... > formatting of the timestamp looks reasonable, but I can never get past ... > the "Wrong data type" exception. ... > public final class HSQLTest { ...
    (comp.lang.java.databases)