String sql="insert into note (id,title,author,content) values (not_sque.nextVal,'?','?','?')";
try {
Connection con=connectionFactory.getconnection();
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, note.getTitle());
ps.setString(2, note.getAuthor());
ps.setString(3, note.getContent());values中的not_sque.nextVal是什么意思?

解决方案 »

  1.   

    这个是Oracle语句吧!not_sque是一个自定义的Sequence,和mysql的auto_increment一样。
      

  2.   

    如果是mysql 改sql语句改如何写?
    这样?
    String sql="insert into note (id,title,author,content) values (auto_increment,'?','?','?')";
      

  3.   

    如果是mysql,第一列在定义时要定义成主键,int类型,auto_increment,插入的时候
    String sql="insert into note (id,title,author,content) values (null,'?','?','?')"; 
    null就行了,mysql会自动生成自增长的值。
      

  4.   

    对了,占位符不需要单引号,即使那列是字符串也不需要
    String sql="insert into note (id,title,author,content) values (null,?,?,?)"; 
      

  5.   

    嘿,谢楼上!你有没有完整的mysql增删查改的完整的例子没给我发份哈,我每次总在sql语句规范着犯愁!
      

  6.   

    可以看mysql官方文档第13章sql语句语法
    http://dev.mysql.com/doc/refman/5.1/zh
      

  7.   

    其实这个我也看过,我就是拿不准insert into talbe_name (id,tietle) values (null,?)还是
    insert into talbe_name (id,tietle) values (null,'?')
    还有"update note set title=?,author=?,concent=? where id=?";
    还是"update note set title='?',author='?',concent='?' where id='?'";
    恩,我仔细看下官方文档先,谢谢了 ,我结贴。
      

  8.   

    一般情况下,用insert into talbe_name (id,tietle) values (null,?)就行!
    insert into talbe_name (id,tietle) values (null,'?') 是标准写法!
    下一句是"update note set title='?',author='?',concent='?' where id='?'"; 对!
    "update note set title=?,author=?,concent=? where id=?"; 错!