SQL异常列计数与第1行的值计数不匹配
在NetBeans 8.2版中,同时使用摆动apk
中的表单。我收到此错误
int i=s.executeUpdate("insert into register(FULL_NAME,EMAIL,PASSWORD,CPASSWORD,MOBILE_NO,GENDER,DEPARTMENT,HOBBIES,ADDRESS) values ('"+fname1+","+email1+","+pass1+","+cpass1+","+num1+","+gender+","+dept1+","+hobby+","+address1+"')");
我希望将值发送到SQL数据库或MySql工作台
答案 0 :(得分:0)
您的表有9列,但您只能将值插入1列。
您应该搜索使用parameterized query
或使用此解决方法(''
引用了参数varchar类型,而数字类型不是)
int i = s.executeUpdate(
"INSERT INTO register(
full_name,
email,
password,
cpassword,
mobile_no,
gender,
department,
hobbies,
address)
VALUES ('"
+ fname1
+ "', '" + email1
+ "', '" + pass1
+ "', '" + cpass1
+ "'," + num1
+ ", '" + gender
+ "', '" + dept1
+ "', '" + hobby
+ "', '" + address1
+ "')"
);
答案 1 :(得分:0)
您可以使用此
int i=s.executeUpdate("insert into register(FULL_NAME,EMAIL,PASSWORD,CPASSWORD,MOBILE_NO,GENDER,DEPARTMENT,HOBBIES,ADDRESS) "
+ "values ('"+fname1+"','"+email1+"','"+pass1+"','"+cpass1+"','"+num1+"','"+gender+"','"+dept1+"','"+hobby+"','"+address1+"')");
根据您当前的情况,您传递的是单一值,而不是9个到期日的'单一报价'
答案 2 :(得分:0)
您的查询在所有字符串串联之后应如下所示:
int i=s.executeUpdate("insert into
register(FULL_NAME,EMAIL,PASSWORD,CPASSWORD,MOBILE_NO,GENDER,DEPARTMENT,HOBBIES,ADDRESS) values ('personName','personalEmail',..))
在SQL中进行查询时,应将每个字符串都用单引号引起来
在您的示例中,连接后将如下所示:
int i=s.executeUpdate("insert into
register(FULL_NAME,EMAIL,PASSWORD,CPASSWORD,MOBILE_NO,GENDER,DEPARTMENT,HOBBIES,ADDRESS) values ('personName,personalEmail,..'))
并会像您仅为第一栏FULL_NAME赋予价值那样解释