我遇到了以下代码,我觉得它做错了:
(请注意,这是 JDK 1.4.2,因此未键入列表)
StringBuffer queryBuffer = new StringBuffer();
ArrayList temp = new ArrayList();
...
queryBuffer.append("and sb.POSTCODE = ? ");
temp.add(postcode);
...
conn = ConnectionManager.getConnection();
pstmt = conn.prepareStatement(queryBuffer.toString());
这就是我所关心的:
for(int i=0; i<temp.size(); i++) {
log.debug("setString("+ (i+1) + "," + (String)temp.get(i) + ")");
pstmt.setString(i+1, (String)temp.get(i));
}
但是我注意到数据库中一些对应的数据类型(字段)是整数,还有日期,这样可以吗?