代码如下:
public boolean insert(CustomerBean customer) {
// TODO Auto-generated method stub
boolean b = false;
String sql = "insert into s_customer values(s_customer_seq.nextval,?,?,?,?,?,?,?,?,?)";
try {
pstam = con.prepareStatement(sql);
System.out.println(pstam);
System.out.println(sql);
pstam.setLong(1, maxId() + 1);
pstam.setString(2,customer.getName());
pstam.setString(3,customer.getIcard() );
pstam.setString(4,customer.getAddress() );
pstam.setString(5, customer.getMobile());
pstam.setString(6,customer.getCompany() );
pstam.setString(7,customer.getPhone() );
pstam.setInt(8, customer.getPost());
pstam.setString(9, customer.getEmail());
System.out.println(sql);
int i = pstam.executeUpdate();
if (i > 0) {
b = true;
}
} catch (SQLException e) {
System.out.println("在对customer表做插入操作的时候出错了" + e.getMessage());
} finally {
DButils.close(con, pstam, null);
}
return b;
}
public boolean insert(CustomerBean customer) {
// TODO Auto-generated method stub
boolean b = false;
String sql = "insert into s_customer values(s_customer_seq.nextval,?,?,?,?,?,?,?,?,?)";
try {
pstam = con.prepareStatement(sql);
System.out.println(pstam);
System.out.println(sql);
pstam.setLong(1, maxId() + 1);
pstam.setString(2,customer.getName());
pstam.setString(3,customer.getIcard() );
pstam.setString(4,customer.getAddress() );
pstam.setString(5, customer.getMobile());
pstam.setString(6,customer.getCompany() );
pstam.setString(7,customer.getPhone() );
pstam.setInt(8, customer.getPost());
pstam.setString(9, customer.getEmail());
System.out.println(sql);
int i = pstam.executeUpdate();
if (i > 0) {
b = true;
}
} catch (SQLException e) {
System.out.println("在对customer表做插入操作的时候出错了" + e.getMessage());
} finally {
DButils.close(con, pstam, null);
}
return b;
}
也就是说你的第一列的值实际上已经有值了,就是s_customer_seq.nextval
select s_customer_seq.nextval into id from dual;