【发布时间】:2014-09-18 19:26:22
【问题描述】:
我尝试过这样做:
query1="INSERT INTO `users`(`email`, `password`, `login`, `familiya`, `name`, `otchestvo`, `age`, `country`, `city`, `mob`, `skype`) VALUES ("+user.getEmail()+","+user.getPassword()+","+user.getLogin()+","+user.getFamiliya()+","+user.getName()+","+user.getOtchestvo()+",11,"+user.getCountry()+","+user.getCity()+","+user.getMob()+","+user.getSkype()+")";
我做错了什么?所有“get”都不为空,只有语法错误。
我想发布数据库的图像,但我需要 10 个声望...
所有字段均为varchar(15),年龄为int(2)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@mail.ru,12345,dima,Dmitriev,dima,Dmitrievich,11,Dmitrountry,Dmitriegrad,2020327' at line 1
【问题讨论】:
-
你的SQL有很多问题,一是Varchar类型应该用单引号括起来。
-
都是varchar吗?
-
不要那样构造你的sql。使用
PreparedStatement。 -
您使用的是哪个数据库?看起来像 MySQL,但是...?
-
您还在为字段使用保留字,例如
password。我建议用[ ]包围他们