2017-09-25 83 views
0

與TIMESTAMP恢復時間利用的HyperSQL不能上的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把日期,時間和時區在該領域「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

我的錯誤是

Date fec = result.getDate("fec_creacion");  

正確的方法是

Timestamp fecx = result.getTimestamp("fec_creacion"); 
Date fec = new Date(fecx.getTime());