mysql中的auto_increment如何重新赋值 ---PreparedStatement的setNull()
来源:互联网 发布:npm i node sass d 编辑:程序博客网 时间:2024/06/11 15:26
public void insert(Note note)throws Exception
{
String sql = "INSERT INTOnote(id,title,author,content) VALUES(?,?,?,?)" ;
PreparedStatement pstmt = null;
DataBaseConnection dbc = null;
dbc = new DataBaseConnection();
try
{
pstmt =dbc.getConnection().prepareStatement(sql);
//关键代码,费了很多时间才找到的解决办法
pstmt.setNull(1,1);
pstmt.setString(2,note.getTitle());
pstmt.setString(3,note.getAuthor());
pstmt.setString(4,note.getContent());
pstmt.executeUpdate();
pstmt.close();
}
catch (Exception e)
{
//System.out.println(e) ;
throw newException("操作中出现错误!!!") ;
}
finally
{
dbc.close();
}
}
ps:1.当已经给auto_increment赋某值时,继续赋相同值给它,会出错。
2.在java中如果要insert一行数据给数据表,且该行有auto_increment,如果auto_increment没有初值,会报错。
如果auto_increment已有值,则sql语句中auto_increment对应的值应为null,如:
con.modify(sql,null,user, password, contact, email);
- mysql中的auto_increment如何重新赋值 ---PreparedStatement的setNull()
- PreparedStatement的setNull
- java.sql.PreparedStatement的setNull用法
- mysql中的auto_increment的问题
- 如何去除mysql中的auto_increment为1
- mysql 的AUTO_INCREMENT如何从0开始
- 调整mysql表中的auto_increment的值
- mysql如何处理auto_increment
- mysql中的auto_increment
- Mysql中的AUTO_INCREMENT
- MySQL的AUTO_INCREMENT
- MySQL的AUTO_INCREMENT
- MySQL的AUTO_INCREMENT
- MySQL的AUTO_INCREMENT
- mysql的auto_increment
- MySQL的AUTO_INCREMENT
- MySQL的AUTO_INCREMENT
- mysql的auto_increment
- 谁是小偷?
- 33 java 数组3
- 获得进程,服务,应用的状态以及获取各种开关的状态,设置开关状态
- 【stagefrightplayer】3 MediaExtractor介绍
- 利用穷举法做等差数列
- mysql中的auto_increment如何重新赋值 ---PreparedStatement的setNull()
- 杭电2802题
- Ubuntu 下使用 Doxygen
- day-03
- xcode设置字体大小
- Hadoop1.0与Hadop2.0架构比较
- 算法之旅,直奔<algorithm>之十九 includes
- 读取沙河文件
- 九阳豆浆机各型号字母数字代表的意思