我想将Informix DATETIME YEAR TO SECOND映射到Java数据类型.
有人可以提供相应的Java数据类型来保存Informix DATETIME YEAR TO SECOND值吗?
答案是:根据我的JDBC驱动程序,java.sql.Time.
解决方法:
我使用Jython和JDBC Informix驱动程序JDBC.3.70.JC1DE.使用元数据的测试代码如下:
db = DriverManager.getConnection(db_url, usr, passwd)
c = db.createStatement()
rs = c.executeQuery(“SELECT * FROM test_datetime”)
rsmd = rs.getMetaData()
print(‘columnCnt: %d’ % (rsmd.getColumnCount()))
while (rs.next()):
for i in range(rsmd.getColumnCount()):
col_no = i + 1
print(“value: [%s]” % rs.getString(col_no))
print(“name: [%s]” % rsmd.getColumnName(col_no))
print(“Java type: %d” % rsmd.getColumnType(col_no))
print(“Java class name: %s” % rsmd.getColumnClassName(col_no))
print(“column type name: %s” % rsmd.getColumnTypeName(col_no))
print(‘-‘ * 20)
有趣的列的输出:
value: [03.01.11]
name: [date_column]
Java type: 91
Java class name: java.sql.Date
column type name: date
——————–
value: [2011-01-03 00:00:00.0]
name: [datetime_yd]
Java type: 93
Java class name: java.sql.Timestamp
column type name: datetime year to day
——————–
value: [2011-01-03 10:28:51.0]
name: [datetime_ys]
Java type: 93
Java class name: java.sql.Timestamp
column type name: datetime year to second
——————–
value: [10:28:51]
name: [datetime_hs]
Java type: 92
Java class name: java.sql.Time
column type name: datetime hour to second
因此,此版本的JDBC驱动程序的正确答案是:datetime至year的秒映射到java.sql.Timestamp.
PS:您写的驱动程序将其映射到java.sql.Time,但也许您使用的是Informix JDBC驱动程序的旧版本?
标签:informix,jdbc,java
来源: https://codeday.me/bug/20191208/2094674.html