【发布时间】:2009-07-31 22:57:17
【问题描述】:
我有这种方法使用 jdbc 插入数据,该方法将根据 java 类型插入值。像这样的:
Object o = map.get( key );
if( o == null ) {
// setNull( index );
} else if( o instanceof String ) {
// setString( index, (String) o );
} else if( o instanceof Timestamp ) {
// setTimestampt( index, ( Timestamp ) o );
} else if( o instanceof Integer ) {
// setInt( index, (Integer) o );
}
index++;
它有一个问题(旁边都是评论:P)
如果o的值为null,我需要使用"setNull(int, int)"方法,但是我必须指定SQL类型:
...注意:您必须指定参数的 SQL 类型。
但是...我不知道类型,所以我正在考虑使用 always VARCHAR(只是因为)
setNull( index,Types.VARCHAR); .
如果我在准备好的语句中始终使用 varchar 设置 null 会发生什么?
我正在使用:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
使用 Oracle JDB 驱动程序:
11.1.0.7.0-Production ( ojdbc6.jar )
还有什么选择?
【问题讨论】:
标签: java jdbc oracle10g prepared-statement