数据类型不一致:预期DATE在插入数据库时​​获得了NUMBER

时间:2014-12-11 19:36:44

标签: oracle jdbc prepared-statement

我试图在数据库表中插入一行,然后继续

ORA-00932: inconsistent datatypes: expected DATE got NUMBER

我不知道为什么会发生这种情况,因为所有日期都是SYSDATE

String insertNewAlarmStat =
        "insert into alarmes (id_alarm, alarm_key, id_notif, sever, urgency, date_hour_start, date_hour_modif, date_hour_end, " +
                "state, state_rec, date_hour_rec,  id_user_rec, id_system_rec, " +
                "type, cause, " +
                "num_events, id_entity_g, type_entity_g, " +
                "desc_entity_g, problem, " +
                "time_urg_act, max_urg_act, time_end, time_arq, lim, rec_oblig, dn, num_events_ps, id_alarm_o, id_notif_o, text_ad, domain, date_hour_reg) " +
                "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, SYSDATE, SYSDATE, SYSDATE, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE)";
PreparedStatement prpstmt = null ;
try {
        prpstmt = conn.prepareStatement(insertNewAlarmStat);

        prpstmt.setInt(1, randomNumberGenerator());
        prpstmt.setString(2, UUID.randomUUID().toString());
        prpstmt.setString(3, UUID.randomUUID().toString());
        prpstmt.setInt(4, randomNumberGenerator());
        prpstmt.setInt(5, 8);
        prpstmt.setInt(6, 8524);
        prpstmt.setString(7, UUID.randomUUID().toString());
        prpstmt.setString(8, UUID.randomUUID().toString());
        prpstmt.setString(9, UUID.randomUUID().toString());
        prpstmt.setString(10, UUID.randomUUID().toString());
        prpstmt.setString(11, "KABOOM");
        prpstmt.setInt(12, 8);
        prpstmt.setInt(13, 43);
        prpstmt.setString(14, UUID.randomUUID().toString());
        prpstmt.setString(15, UUID.randomUUID().toString());
        prpstmt.setString(16, UUID.randomUUID().toString());
        prpstmt.setString(17, UUID.randomUUID().toString());
        prpstmt.setInt(18, 2);
        prpstmt.setInt(19, 224);
        prpstmt.setInt(20, 2);
        prpstmt.setInt(21, 224);            
        prpstmt.setInt(22, 2);
        prpstmt.setInt(23, 224);            
        prpstmt.setInt(24, 2);  
        prpstmt.setString(25, UUID.randomUUID().toString());
        prpstmt.setString(26, UUID.randomUUID().toString());
        prpstmt.setString(27, UUID.randomUUID().toString());
        prpstmt.setInt(28, 2);

        prpstmt.executeUpdate();
} catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

我试过这种方式,我试图删除SYSDATE并添加一些:

prpstmt.setDate(number, getCurrentDate()); //getCurrent date returns sql.Date

但是,错误是相同的

我已经调试了一段时间了,我似乎无法找到问题,我错过了什么?

1 个答案:

答案 0 :(得分:1)

检查列的位置与您为数据类型协议发送的值的比较。