problem with timestamps in HSQL
- From: "sean" <s_machin@xxxxxxxxxxx>
- Date: 24 Jun 2005 22:23:13 -0700
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();
}
}
.
- Follow-Ups:
- Re: problem with timestamps in HSQL
- From: fredt
- Re: problem with timestamps in HSQL
- From: joeNOSPAM@xxxxxxx
- Re: problem with timestamps in HSQL
- Prev by Date: HSQDB 1.8.0 RC12 Released--Probabl Final Release Candidate for this Veersion Cycle
- Next by Date: Re: problem with timestamps in HSQL
- Previous by thread: HSQDB 1.8.0 RC12 Released--Probabl Final Release Candidate for this Veersion Cycle
- Next by thread: Re: problem with timestamps in HSQL
- Index(es):
Relevant Pages
|
|