1 16 package com.ibatis.sqlmap.engine.type; 17 18 import com.ibatis.sqlmap.client.SqlMapException; 19 20 import java.sql.*; 21 import java.text.DateFormat ; 22 import java.text.ParseException ; 23 import java.text.SimpleDateFormat ; 24 25 28 public class SqlTimeTypeHandler extends BaseTypeHandler implements TypeHandler { 29 30 private static final String DATE_FORMAT = "hh:mm:ss"; 31 private static final DateFormat format = new SimpleDateFormat (DATE_FORMAT); 32 33 public void setParameter(PreparedStatement ps, int i, Object parameter, String jdbcType) 34 throws SQLException { 35 ps.setTime(i, (java.sql.Time ) parameter); 36 } 37 38 public Object getResult(ResultSet rs, String columnName) 39 throws SQLException { 40 Object sqlTime = rs.getTime(columnName); 41 if (rs.wasNull()) { 42 return null; 43 } else { 44 return sqlTime; 45 } 46 } 47 48 public Object getResult(ResultSet rs, int columnIndex) 49 throws SQLException { 50 Object sqlTime = rs.getTime(columnIndex); 51 if (rs.wasNull()) { 52 return null; 53 } else { 54 return sqlTime; 55 } 56 } 57 58 public Object getResult(CallableStatement cs, int columnIndex) 59 throws SQLException { 60 Object sqlTime = cs.getTime(columnIndex); 61 if (cs.wasNull()) { 62 return null; 63 } else { 64 return sqlTime; 65 } 66 } 67 68 public Object valueOf(String s) { 69 try { 70 java.util.Date date = format.parse(s); 71 return new Time(date.getTime()); 72 } catch (ParseException e) { 73 throw new SqlMapException("Error parsing default null value date. Format must be '" + DATE_FORMAT + "'. Cause: " + e); 74 } 75 } 76 77 } 78 | Popular Tags |