我正在使用以下命令将记录插入我的数据库:
PreparedStatement stmt = null;
Connection conn = null;
HashMap<String, Object> hoursMap = new HashMap<String, Object>();
hoursMap.put("PLACE_ID", hours.getPlaceID());
hoursMap.put("DAY", hours.getDayID());
hoursMap.put("TIME_OPEN", hours.getTimeOpen());
hoursMap.put("TIME_CLOSE", hours.getTimeClose());
String insertStr = StatementCreator.insertQueryGenerator("HOURS",
hoursMap);
try {
conn = ConnectionManager.getConnection();
stmt = StatementCreator.createStatement(conn, insertStr, hoursMap,
false);
returnVal = stmt.execute();
ConnectionManager.closeStatement(stmt);
System.out.println("Created");
} catch (SQLException e) {
System.out.println("ERROR");
e.printStackTrace();
} finally {
ConnectionManager.closeConnection(conn);
}
return returnVal;
}
但是,在运行此程序时,我收到以下错误:
org.postgresql.util.PSQLException:错误:列“TIME_OPEN”是带时区的时间类型,但表达式的类型是字符变化
提示:您需要重写或强制转换表达式。职位:71
我想不通是为什么?我这么说的原因是,如果我进入调试模式并查看内部准备好的语句,我会看到以下内容:
INSERT INTO "HOURS" ("TIME_OPEN","DAY","TIME_CLOSE","PLACE_ID")VALUES('11:30:00-0400',6,'23:59:59-0400',541)
我将它复制/粘贴到我的 SQL 编辑器中,它会运行并插入记录。
有什么我想念的吗?