如何 更新一条数据 向数据库
public class productDao {
public static void main(String [] args){
productDao p=new productDao();
beanProduct bean= new beanProduct();
bean.setDid("12345");
//p.sum();
//p.sumdange();
//System.out.print(p.sumdange());
beanProduct bea =new beanProduct();
p.updateProduct(bea);
System.out.print( p.updateProduct(bea));
}
public boolean updateProduct(beanProduct bean){
Connection conn = DBConn.getConn();
try {
PreparedStatement pstmt=conn.prepareStatement(" update [Product] set p_name=? where p_id=?");
pstmt.setString(1, bean.getDid());
pstmt.setString(3, bean.getName());
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}finally{
DBConn.CloseConn();
}
}
异常
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setNull(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setString(Unknown Source)
at (productDao.java:206)
at (productDao.java:26)