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

jsp中的SQL插入语句怎么编写
CREATE TABLE note
(
id int not null primary key ,
title varchar(20) not null ,
author varchar(20) not null ,
content varchar(50) not null 
) ;


String sql = "INSERT INTO note VALUES(???????)" ;
VALUES里面怎么写??

------解决方案--------------------
insert into note values(?,?,?,?)

你有两种方式:

第一种直接拼
insert into note values(1,'test','test','test')

第二种防注入的方式:
insert into note values(?,?,?,?)
------解决方案--------------------
探讨

insert into note values(?,?,?,?)

你有两种方式:

第一种直接拼
insert into note values(1,'test','test','test')

第二种防注入的方式:
insert into note values(?,?,?,?)

------解决方案--------------------
Connection ct=new ConnDB().getConn();
Statement sm=ct.createStatement();
sm.executeUpdate("insert into UserJSP values('"+a+"','"+a1+"','"+a2+"','"+a3+"')");

这段代码你看啦 楼主应该懂啦吧 最后一条语句返回一个int值 返回1就说明成功加入一条数据!!UserJSP这个是表名 ()是字段的值