java链接mysql

 if(choice  == 1){
    System.out.println("请输入要删除的学号");
     int  no = scanner.nextInt();
     sql = " delete from students where sno = " +no+ ' ';
            }

   sql = " delete from students where sno = "+no+ ' ';
  //这句sql语句写成下面这样 删除就失效了?
   sql = " delete from students where sno =  '"+no+ "'";
原因是啥呀?

如果 no = 1;
sql = " delete from students where sno = "+no+ ' '; ==> delete from students where sno = 1
sql = " delete from students where sno = '"+no+ "'"; ==> delete from students where sno = '1'
因为sno需要的是数字 1,而下边的语句变成了字符串 '1' 所以会执行失败了

你数据库 sno 数据类型的问题 数值不需要用引号 字符串、时间类型 或者其他类型 需要用引号