是向数据库中插入一条数据,包的错误说在''附近有错误,但我的sql语句没有使用单引号,纠结好几天了,跪求解答!
这个是数据库的表
create table org_user(
user_id int primary key auto_increment,
regin_name nvarchar(20),
passwd varchar(12),
email varchar(20),
question nvarchar(20),
answer nvarchar(20),
name nvarchar(20),
gender nchar(1),
birthday date);
然后根据这个表建立一个对象,这个是对象的代码
public class RegUser {
private Integer userID;
private String resName;
private String passwd;
private String email;
private String question;
private String answer;
private String name;
private Date brith;
private char gender;
public RegUser() {
super();
}
@Override
public String toString() {
return "RegUser [userID=" + userID + ", resName=" + resName + ", passwd=" + passwd + ", email=" + email
+ ", question=" + question + ", answer=" + answer + ", name=" + name + ", brith=" + brith + ", gender="
+ gender + "]";
}
public RegUser(Integer userID, String resName, String passwd, String email, String question, String answer,
String name, Date brith, char gender) {
super();
this.userID = userID;
this.resName = resName;
this.passwd = passwd;
this.email = email;
this.question = question;
this.answer = answer;
this.name = name;
this.brith = brith;
this.gender = gender;
}
public Integer getUserID() {
return userID;
}
public void setUserID(Integer userID) {
this.userID = userID;
}
public String getResName() {
return resName;
}
public void setResName(String resName) {
this.resName = resName;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBrith() {
return brith;
}
public void setBrith(Date brith) {
this.brith = brith;
}
public char getGender() {
return gender;
}
public void setGender(char gender) {
this.gender = gender;
}
}
下面是在mapper中的配置
<resultMap id="RegUserMap" type="RegUser">
<id column="user_id" property="userID"/>
<result column="regin_name" property="resName"/>
<result column="passwd" property="passwd"/>
<result column="email" property="email"/>
<result column="question" property="question"/>
<result column="answer" property="answer"/>
<result column="name" property="name"/>
<result column="gender" property="gender"/>
<result column="birthday" property="brith"/>
</resultMap>
<insert id="add" parameterType="com.musen.blog.bean.RegUser">
insert into org_user(regin_name,passwd,email,question,answer,name,gender,birthday)
values(#(resName),#(passwd),#(email),#(question),#(answer),#(name),#(gender),#(brith))
</insert>
然后报的错误是
Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException:
Error updating database. Cause: java.sql.SQLSyntaxErrorException: (conn=55) 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 '' at line 2
The error may exist in file [E:\crazy11\blog\target\classes\com\musen\blog\bean\RegUserMapper.xml]
The error may involve com.musen.blog.bean.RegUserMapper.add-Inline
The error occurred while setting parameters
SQL: insert into org_user(regin_name,passwd,email,question,answer,name,gender,birthday) values(#(resName),#(passwd),#(email),#(question),#(answer),#(name),#(gender),#(brith))
Cause: java.sql.SQLSyntaxErrorException: (conn=55) 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 '' at line 2
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: (conn=55) 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 '' at line 2