看看在jsp中这个数据库插入语句有什么错误
环境:mysql,tomcat,jsp
news_index表已经建立起来
DROP TABLE IF EXISTS news_index;
CREATE TABLE news_index(news_id int(10) NOT NULL auto_increment,type_id int(10) not null,
news_title varchar(100) default NULL,news_source varchar(100) default NULL,news_author
varchar(100) default NULL,news_time datetime default NULL,news_audit int(10) default NULL,
PRIMARY KEY (news_id),KEY news_type_id (type_id))TYPE=MyISAM;
错误语句:
sql = "insert into news_index values('',"+type_id+","+news_title+","+news_source+","+news_author+"',now(),'"+Integer.parseInt(news_audit)+"')";
NewsBean.executeUpdate(sql);
出错信息:
连接数据库失败了,异常为:Syntax error or access violation, message from server
: "You have an error in your SQL syntax. Check the manual that corresponds to y
our MySQL server version for the right syntax to use near '?????,?????,?????,now
(),'1')' at line 1"
连接数据库失败了,异常为:Syntax error or access violation, message from server
: "You have an error in your SQL syntax. Check the manual that corresponds to y
our MySQL server version for the right syntax to use near ')' at line 1"
问题点数:30、回复次数:5Top
1 楼NetRep_Loser(领悟非凡)回复于 2005-05-27 15:25:13 得分 5
int不用制订长度吧Top
2 楼NetRep_Loser(领悟非凡)回复于 2005-05-27 15:29:12 得分 5
sql = "insert into news_index values(,"+type_id+",'"+news_title+"','"+news_source+"','"+news_author+"','"+now()"',"+Integer.parseInt(news_audit)+")";Top
3 楼chris_zjy(笑鱼)回复于 2005-05-27 15:29:14 得分 10
sql = "insert into news_index values('',"+type_id+","+news_title+","+news_source+","+news_author+"',now(),'"+Integer.parseInt(news_audit)+"')";
sql语句出错,楼主仔细查查,可以打印出来,看得比较清楚
估计是引号的个数不匹配 这里“ +","+news_author+"'”
Top
4 楼NetRep_Loser(领悟非凡)回复于 2005-05-27 15:33:14 得分 10
又错.....
不对....
sql = "insert into news_index(type_id,news_title,news_source,news_author,news_time,news_audit) values("+type_id+",'"+news_title+"','"+news_source+"','"+news_author+"','"+now()+"',"+Integer.parseInt(news_audit)+")";
Top
5 楼water2004(@-@)回复于 2005-05-27 16:42:37 得分 0
sql = "insert into news_index values('',"+type_id+",'"+news_title+"','"+news_source+"','"+
news_author+"',now(),'"+Integer.parseInt(news_audit)+"')";
弄好了,这样对了。谢谢各位Top




