我有一个带有以下方案的oracle数据库:
我使用以下方法在数据库中进行一些插入。
private void insert(String folder, int seconds) throws SQLException {
stm = connection.prepareStatement("INSERT INTO DM_PROCMON (DM_ID,t_ID, WORKFLOW, TECHNOLOGY, NAME_EVENT, TIME_EVENT) VALUES(DM_ID.nextval,'?', 'up', 'Folder','?', ?)");
stm.setString(1, String.format("%d%d%d.txt",random.nextInt(999),random.nextInt(999),random.nextInt(999)));
stm.setString(2, folder);
stm.setTime(3, new Time(seconds * 1000));
stm.execute();
}
我得到的是一个SQL异常,它说:
java.sql.SQLException:列索引无效
当我调试时,我看到它就行了:
stm.setString(2,folder);
我不知道问题所在。
答案 0 :(得分:1)
删除?
周围的顶点stm = connection.prepareStatement("INSERT INTO DM_PROCMON (DM_ID,t_ID, WORKFLOW, TECHNOLOGY, NAME_EVENT, TIME_EVENT) VALUES(DM_ID.nextval,?, 'up', 'Folder',?, ?)");
再试一次。
是setString
的方法PreparedStatement
,可以为您处理任何字符串周围的顶点。