日期:2014-05-17  浏览次数:20687 次

语法错误,请帮忙看一下
关键语句:String strSql="insert into "+tbName
  +" (ID,Exp,LastVisIP,LeftTime,LoginCount,NickName,Password,"
  +"PostCount,Email,UserName,RegisterDate) values("
  +id+","+exp+","+lastvisip+","+lefttime+","
  +logincount+","+nickname+","+password+","
  +postcount+","+email+","+username+","
  +registerdate+")";
  System.out.println(strSql);

执行后提示语句:

insert into users (ID,Exp,LastVisIP,LeftTime,LoginCount,NickName,Password,PostCount,Email,UserName,RegisterDate) values(1,0,unknown,2012-10-30 15:14:25.362,0,nickname,unknown,0,aa@bb.cc,username,2012-10-30 15:14:25.362)

executeUpdate: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 '15:14:25.362,0,nickname,unknown,0,aa@bb.cc,username,2012-10-30 15:14:25.362)' at line 1


------解决方案--------------------
楼主,你太牛逼了,你这写法全当字段都是数值型的了!
字符型要转成字符串,日期型要转换成日期!
如(加如tbName变量里表的字段id是数值型,exp是字符型):"insert into "+tbName+" (ID,Exp) values ("+id+",'"+exp+"')";