插入数据的问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public class InsertCommand implements Command{ @Override public void execute() { Scanner in = new Scanner(System.in); System.out.println( "商品名称:" ); String name = in.next(); System.out.println( "商品价格:" ); Float price = in.nextFloat(); System.out.println( "商品描述:" ); String desp = in.next(); Connection connection = null ; PreparedStatement pstmt = null ; try { connection = DbUtils.getConnection(); String sql = "INSERT INTO goods SET name = ?, price = ?, desp = ?" ; pstmt = connection.prepareStatement(sql); pstmt.setString( 1 ,name); pstmt.setFloat( 2 ,price); pstmt.setString( 3 ,desp); int cnt = pstmt.executeUpdate(); } catch (Exception e){ e.printStackTrace(); } finally { DbUtils.closeConnection(connection,pstmt, null ); } } } |
按以上代码插入数据后。我在Navicat中执行了删除语句把耳机这条记录删除。然后再在idea重新插入耳机数据后,他的id就变成了6,而不是5。再重复一遍,id就有变成了7,请问这个怎么解决呢
9
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧