通过索引访问的Java pstmt sqlUpdate

时间:2015-02-02 21:23:25

标签: java sql oracle prepared-statement

我正在尝试使用sql prepared语句更新数据库,但问题是索引访问了这些参数。我正在尝试执行以下操作:

String sql = 
"UPDATE table1
SET par1 = ?,
SET par2 = ?,
SET par3 = ?,

WHERE par4 =?"

但问题是我正在添加一个列并将其映射到par5。我怎样才能在这个sql语句中设置这个参数?

2 个答案:

答案 0 :(得分:0)

String sql = "UPDATE table1 SET par1 = ?, par2 = ?, par3 = ?,WHERE par4 =?"

答案 1 :(得分:0)

PreparedStatement pstmt = null;
String sql = "UPDATE table1 SET par1 = ?, par2 = ?, par3 = ?, par5 = ? WHERE par4 =?"
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, par1);
pstmt.setString(2, par2);
pstmt.setString(3, par3);
pstmt.setString(4, par5);
pstmt.setString(5, par4);
pstmt.executeUpdate();