使用Hypersql
我创建了一个像:
的表int result = stmt.executeUpdate("CREATE CACHED TABLE solicitudes ( "+
"id VARCHAR(36) NOT NULL, extid VARCHAR(36), operacion VARCHAR(15) NOT NULL, "+
"imsi VARCHAR(20),msisdn VARCHAR(20),spid VARCHAR(20),prtb VARCHAR(20),imsiNuevo VARCHAR(20),"
+ "msisdnNuevo VARCHAR(20), fec_creacion TIMESTAMP WITH TIME ZONE NOT NULL, fec_lstUpdate TIMESTAMP WITH TIME ZONE,"
+ "estado VARCHAR(2),etapa VARCHAR(30),subetapa VARCHAR(30), reintentos INT,"
+ "codresp VARCHAR(20),descresp VARCHAR(100), "+
"PRIMARY KEY (id));");
fec_creacion在哪里
fec_creacion TIMESTAMP WITH TIME ZONE NOT NULL
然后我插入了一行,如:
String strSQL="INSERT INTO solicitudes VALUES ( "
+ " '"+id+"',"
+ " '"+sol.getIdext()+"',"
+ " '"+sol.getOperacion()+"',"
+ " '"+sol.getImsi()+"',"
+ " '"+sol.getMsisdn()+"',"
+ " '"+sol.getSpid()+"',"
+ " '"+sol.getPrtb()+"',"
+ " '"+sol.getImsiNuevo()+"',"
+ " '"+sol.getMsisdnNuevo()+"',"
+ " CURRENT_TIMESTAMP , NULL,'-','-','-',0,"
+ " '"+r.getCodigo()+"',"
+ " '"+r.getDescripcion()+"');";
st.executeUpdate(strSQL);
我猜CURRENT_TIMESTAMP将DATE,时间和时区放在字段中" fec_creacion"
然后,我从表中恢复数据:
ResultSet result = st.executeQuery("Select id,extid,operacion,fec_creacion,fec_lstUpdate,estado,etapa,subetapa,reintentos FROM SOLICITUDES ORDER BY fec_creacion desc LIMIT 5");
while(result.next()){
Date fec = result.getDate("fec_creacion");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
String sfec=dateFormat.format(fec);
System.out.println(" fecc="+sfec);
}
但是日志显示fecc没有时间
fecc=2017-09-25T00:00:00-03:00
我在代码的另一部分测试了SimpleDateFormat的模式,并且没问题。
答案 0 :(得分:0)
我的错误是
Date fec = result.getDate("fec_creacion");
正确的方法是
Timestamp fecx = result.getTimestamp("fec_creacion");
Date fec = new Date(fecx.getTime());