01: package adhoc;
02:
03: import java.sql.Connection;
04: import java.sql.DriverManager;
05: import java.sql.PreparedStatement;
06: import java.sql.ResultSet;
07: import java.sql.SQLException;
08: import java.sql.Statement;
09: import java.sql.Time;
10:
11: import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
12:
13: public class InformixTimeTypeTest {
14:
15: String jdbcUrl = "jdbc:informix-sqli:192.168.1.100:9088/dbcopydest:INFORMIXSERVER=sockets_srvr";
16:
17: String user = "informix";
18:
19: String pass = "password";
20:
21: Connection con = null;
22:
23: String dropSQL = "drop table time_table ";
24:
25: String createTableSQL = "CREATE TABLE time_table ( time_column datetime hour to second) ";
26:
27: String insertSQL = "insert into time_table (time_column) "
28: + "values (?) ";
29:
30: String selectSQL = "select time_column from time_table ";
31:
32: public InformixTimeTypeTest() throws Exception {
33: init();
34: }
35:
36: public void init() throws Exception {
37: Class.forName("com.informix.jdbc.IfxDriver");
38: con = DriverManager.getConnection(jdbcUrl, user, pass);
39: }
40:
41: /**
42: * This fails with a Connection failure - java.io.EOFException
43: * @throws SQLException
44: */
45: public void doTest() throws SQLException {
46: Statement stmt = null;
47: try {
48: stmt = con.createStatement();
49: stmt.execute(dropSQL);
50: } catch (SQLException e) {
51: e.printStackTrace();
52: } finally {
53: SQLUtilities.closeStatement(stmt);
54: }
55: try {
56: stmt = con.createStatement();
57: stmt.execute(createTableSQL);
58: } catch (SQLException e) {
59: e.printStackTrace();
60: } finally {
61: SQLUtilities.closeStatement(stmt);
62: }
63: PreparedStatement pstmt = null;
64: ResultSet rs = null;
65: try {
66: pstmt = con.prepareStatement(insertSQL);
67: Time time = new Time(System.currentTimeMillis());
68: pstmt.setTime(1, time);
69: pstmt.executeUpdate();
70:
71: rs = stmt.executeQuery(selectSQL);
72: if (rs.next()) {
73: java.sql.Timestamp ts = rs.getTimestamp(1);
74: System.out.println("ts=" + ts);
75: }
76: } catch (SQLException e) {
77: e.printStackTrace();
78: } finally {
79: SQLUtilities.closeResultSet(rs);
80: SQLUtilities.closeStatement(pstmt);
81: }
82: }
83:
84: public void shutdown() throws SQLException {
85: con.close();
86: }
87:
88: /**
89: * @param args
90: */
91: public static void main(String[] args) throws Exception {
92: InformixTimeTypeTest test = new InformixTimeTypeTest();
93: test.doTest();
94: test.shutdown();
95: }
96:
97: }
|