我正在尝试将 java 连接到 sql。虽然我是 javam 的新手,但我似乎无法找出原因。
java.lang.ArrayIndexOutOfBoundsException: 2
你能帮助我并告诉我如何解决这个问题吗?
try{
Connection con = dbConnection();
String lname = this.last.getText();
String fname = this.first.getText();
String mname = this.mid.getText();
String ad = this.add.getText();
String bd = this.bday.getText();
String ag = this.edad.getText();
String nom = this.no.getText();
String per = this.person.getText();
String query = "INSERT INTO Personal Category (Lastname,Firstname,Middle,Address,Birthday,Age,No,Person) VALUES (?,?)"; //to insert to database
PreparedStatement pre;
pre = con.prepareStatement(query);
pre.setString(1, lname);
pre.setString(2, fname);
pre.setString(3, mname);
pre.setString(4, ad);
pre.setString(5, bd);
pre.setString(6, ag);
pre.setString(7, nom);
pre.setString(8, per);
pre.execute();//execute
con.close();
}catch (Exception e){
System.out.println(e);
}
}