我有这个数据库表:
create table users(
id int not null auto_increment,
fn varchar(30),
ln varchar(30),
sex char,
email varchar(60),
country varchar(40),
username varchar(30),
password varchar(100),
primary key(id)
);
运行此代码时,出现错误:参数索引超出范围(8 > 参数数量,即 7)。我也尝试过改变setString(1,fn)
,但它不起作用。
try{
String INSERT="INSERT INTO users (fn,ln,,sex,email,country,username,password) VALUES (?,?,?,?,?,?,?)";
PreparedStatement pst=conn.prepareStatement(INSERT);
System.out.println("Created prepared statement");
pst.setString(2,"fn");
pst.setString(3,"ln");
pst.setString(4,"sex");
pst.setString(5,"email");
pst.setString(6,"country");
pst.setString(7,"username");
pst.setString(8,"password)");
pst.executeUpdate();
}