System.out.println("#aaaaaaaaaaaaaaaaaaaaaaaaaqqqqqqqqqqqqqqqqqqqa");
int result = -1; // 定义保存返回值的变量
try {
System.out.println("ssssssssssssssss");
conn = getConnection();// 调用getConnection()方法构造Connection对象的一个实例conn
System.out.println("00000000000000000000000");
sts = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
System.out.println("1111111111111111111111111111a");
result = sts.executeUpdate(sql); //执行更新操作,用于向数据表中插入数据
sts.close();
Statement stm = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
System.out.println("22222222222222222222222222222");
[color=#00FF00] String ID = "select @@IDENTITY as id";
rs = stm.executeQuery(ID);
if (rs.next()) {
int autoID = rs.getInt("id");
System.out.println("ASDFSFDGSGA"+autoID);
result = autoID;
System.out.println(result);
}
/******************************************************************/
}
catch (SQLException ex) {
result = 0;
}
System.out.println(result); return result;// 返回保存返回值的变量
}[/color]
public String insert(ScripForm SF) {
int ss = getRSCount()+1;
System.out.println(ss);
String str = "";
String datetime = getNow();
try {
// String sql = "INSERT INTO tb_scrip values (18,'00','111','00000000000000',0,2,'2013-03-25 13:48:24',0)"; String sql = "INSERT INTO tb_scrip ('id','wishMan','wellWisher','content','color','face','sendTime','hits') values ("+ss+",'"
+ SF.getWishMan()
+ "','"
+ SF.getWellWisher()
+ "','"
+ SF.getContent() + "',"
+ SF.getColor()
+ ","
+ SF.getFace()
+ ",'"+datetime+"',0)";
System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
int flag = conn.executeUpdate_id(sql);
if (flag > 0) {
str = "恭喜您,贴字条成功,请记住您的字条编号:[" + flag + "]";
} else {
str = "很报谦,您的字条发送失败!";
System.out.println("################################a");
}
System.out.println("添加字条信息的SQL:" + sql);
} catch (Exception e) {
str = "很报谦,您的字条发送失败!";
System.out.println("添加字条时的错误提示:" + e.getMessage());
}
//conn.close();
System.out.println(str);
return str;
}
为什么红色的sql语句可以输入到数据库中,执行结果如下
执行的SQL语句:SELECT * FROM tb_scrip
14
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#aaaaaaaaaaaaaaaaaaaaaaaaaqqqqqqqqqqqqqqqqqqqa
ssssssssssssssss
00000000000000000000000
1111111111111111111111111111a
0
################################a
添加字条信息的SQL:INSERT INTO tb_scrip ('id','wishMan','wellWisher','content','color','face','sendTime','hits') values (14,'00','匿名','dddd',0,0,'2013-03-25 16:27:35',0)
很报谦,您的字条发送失败!
祝福对象:00祝福者:匿名字条颜色:0心情图案:0字条内容:dddd
9 个解决方案
#1
有没有客户端啥的,设置下,打开表结构,直接设置。
#2
创建个索引 create sequence seq_temp;
INSERT INTO tb_scrip ('id','wishMan','wellWisher','content','color','face','sendTime','hits') values (seq_temp.nextval,'00','匿名','dddd',0,0,'2013-03-25 16:27:35',0)
INSERT INTO tb_scrip ('id','wishMan','wellWisher','content','color','face','sendTime','hits') values (seq_temp.nextval,'00','匿名','dddd',0,0,'2013-03-25 16:27:35',0)
#3
建议用SQLyog 链接之后 编辑表 自动增长选中 即可
#4
设置了呀!id就是主键非空,自动递增!
#5
INSERT INTO tb_scrip ('id','wishMan','wellWisher','content','color','face','sendTime','hits') values (14,'00','匿名','dddd',0,0,'2013-03-25 16:27:35',0)
('id','wishMan','wellWisher','content','color','face','sendTime','hits') 引号都去掉。
('id','wishMan','wellWisher','content','color','face','sendTime','hits') 引号都去掉。
#6
执行的SQL语句:SELECT * FROM tb_scrip
14
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#aaaaaaaaaaaaaaaaaaaaaaaaaqqqqqqqqqqqqqqqqqqqa
ssssssssssssssss
00000000000000000000000
1111111111111111111111111111a
22222222222222222222222222222
ASDFSFDGSGA0
0
0
################################a
添加字条信息的SQL:INSERT INTO tb_scrip (id,wishMan,wellWisher,content,color,face,sendTime,hits) values (14,'qq','匿名','qq',0,0,'2013-03-25 17:09:42',0)
很报谦,您的字条发送失败!
祝福对象:qq祝福者:匿名字条颜色:0心情图案:0字条内容:qq
可以读到数据库中,但是还有问题
14
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#aaaaaaaaaaaaaaaaaaaaaaaaaqqqqqqqqqqqqqqqqqqqa
ssssssssssssssss
00000000000000000000000
1111111111111111111111111111a
22222222222222222222222222222
ASDFSFDGSGA0
0
0
################################a
添加字条信息的SQL:INSERT INTO tb_scrip (id,wishMan,wellWisher,content,color,face,sendTime,hits) values (14,'qq','匿名','qq',0,0,'2013-03-25 17:09:42',0)
很报谦,您的字条发送失败!
祝福对象:qq祝福者:匿名字条颜色:0心情图案:0字条内容:qq
可以读到数据库中,但是还有问题
#7
下个navicat很简单
#8
sql语句 id后面加这个:auto_increment
#9
use test;
create table t_test(
id int auto_increment not null,
name varchar(20),
primary key (id)
);
insert into t_test(
name
)
values('name1');
commit;
#1
有没有客户端啥的,设置下,打开表结构,直接设置。
#2
创建个索引 create sequence seq_temp;
INSERT INTO tb_scrip ('id','wishMan','wellWisher','content','color','face','sendTime','hits') values (seq_temp.nextval,'00','匿名','dddd',0,0,'2013-03-25 16:27:35',0)
INSERT INTO tb_scrip ('id','wishMan','wellWisher','content','color','face','sendTime','hits') values (seq_temp.nextval,'00','匿名','dddd',0,0,'2013-03-25 16:27:35',0)
#3
建议用SQLyog 链接之后 编辑表 自动增长选中 即可
#4
设置了呀!id就是主键非空,自动递增!
#5
INSERT INTO tb_scrip ('id','wishMan','wellWisher','content','color','face','sendTime','hits') values (14,'00','匿名','dddd',0,0,'2013-03-25 16:27:35',0)
('id','wishMan','wellWisher','content','color','face','sendTime','hits') 引号都去掉。
('id','wishMan','wellWisher','content','color','face','sendTime','hits') 引号都去掉。
#6
执行的SQL语句:SELECT * FROM tb_scrip
14
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#aaaaaaaaaaaaaaaaaaaaaaaaaqqqqqqqqqqqqqqqqqqqa
ssssssssssssssss
00000000000000000000000
1111111111111111111111111111a
22222222222222222222222222222
ASDFSFDGSGA0
0
0
################################a
添加字条信息的SQL:INSERT INTO tb_scrip (id,wishMan,wellWisher,content,color,face,sendTime,hits) values (14,'qq','匿名','qq',0,0,'2013-03-25 17:09:42',0)
很报谦,您的字条发送失败!
祝福对象:qq祝福者:匿名字条颜色:0心情图案:0字条内容:qq
可以读到数据库中,但是还有问题
14
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#aaaaaaaaaaaaaaaaaaaaaaaaaqqqqqqqqqqqqqqqqqqqa
ssssssssssssssss
00000000000000000000000
1111111111111111111111111111a
22222222222222222222222222222
ASDFSFDGSGA0
0
0
################################a
添加字条信息的SQL:INSERT INTO tb_scrip (id,wishMan,wellWisher,content,color,face,sendTime,hits) values (14,'qq','匿名','qq',0,0,'2013-03-25 17:09:42',0)
很报谦,您的字条发送失败!
祝福对象:qq祝福者:匿名字条颜色:0心情图案:0字条内容:qq
可以读到数据库中,但是还有问题
#7
下个navicat很简单
#8
sql语句 id后面加这个:auto_increment
#9
use test;
create table t_test(
id int auto_increment not null,
name varchar(20),
primary key (id)
);
insert into t_test(
name
)
values('name1');
commit;