jsp报错 MySQL server version for the right syntax to use near 'null')' at line 1完整的报错是:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ve

来源:学生作业帮助网 编辑:作业帮 时间:2024/07/21 15:10:37
jsp报错 MySQL server version for the right syntax to use near 'null')' at line 1完整的报错是:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ve
xXmo+( w-Akh$uE?{"mꎺ;:Vrʲ&vYn#G0"ElȖ#Nԧ݊EQʟ.gvgfgooz|Pg>T>%`E+=Wឯ%Rn/) J[T*\zwi7~Pϯ7 &*yvj(hj{_R]%"*^WRAbn WP@ﳠNMWu8D?5ەTrDJԱб4zh}Q$t0~wP H66ꋂxDߨ/7釂͵\cB#jR.]+Ţ|ѶaK`PW O(G()_vǔĻYg51ž'd~o慃M9bH7ULq6Q8A3 s'5.U8.o2C*m_@|fD)*S6_(D+6^ml7E {/+ڝn޾D)Js銓BţRPTjip4/| Q=ѿqd_sR ^nמH8sE . g}V>svfqWĄdJ hz68%E29l?j12Gm}k-]v) |.j 2~rU5a2M}&8%z3Qin+8.ڄl\z^dΥ3"d#XZ#9OEvځR@q}GGj_50/(, әtt| g٧9w=n6f486ϰ:FR3 Xx-$,a7i,{pd,&4@qHKӡ5:9fDQ~Ÿ|L;hYv# Hc Mm1S0AΉyF |Z̔°*/'_*WK^yN-/W— t"v8t`n`ẖ Lg[gUlp]#a"L:5aT?_PXOX4=b4HSuJ 0FmQ {<ՎlGa&*X&[ST@1lGs 6̦:#M,e]8;K'g&™BpY13zޜ9e.2%jL5 !#`3Cn ۢIUbCD_wH,PBB-nIpB=byohDô1יjdٖY PӰjm! b5b- ]8;KgHt kP0pLQN|:æc. TP/$-h[ TbȩjDlPg$!C&r aؘ i=b`uf4QZ9d.6>@bbPfSC6n؄MtZ3K7:P=5.~2- oף'w7Ƴ"QonH^@ WU43ɋTVܫV$4|'}vʼ=+Pv*AzroTp^D٨_)a a'Fc&1~Yf+{|bQr[Lgv-[ID@20sd3-&);Mj'Zh"DTڌE/o)>^tkuTYu~3

jsp报错 MySQL server version for the right syntax to use near 'null')' at line 1完整的报错是:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ve
jsp报错 MySQL server version for the right syntax to use near 'null')' at line 1
完整的报错是:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version for
the right syntax to use near 'null')' at line 1


应该是我的sql语言写错了,这个是向shop表添加字段的.




 
     <%  
      String shopname=request.getParameter("shopname");
   
      String price=request.getParameter("Price");
      
      String number=request.getParameter("number");
      
      String brand=request.getParameter("brand");
      
      String date=request.getParameter("date");
   
   






 String DBDRIVER = "com.mysql.jdbc.Driver";


//定义连接的mysql数据库
 String DBURL ="jdbc:mysql://localhost:3306/project_314_422";
 String DBUSER ="root";
 String DBPASSWORD ="123";
 Connection conn = null;
 Statement stmt = null;
 PreparedStatement pstmt=null;




 try
 {


  Class.forName(DBDRIVER);


//连接数据库需要使用到数据源,用户名,密码
  conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);


//把数据加进数据库.


  pstmt=conn.prepareStatement("select username from user where username=?");
  pstmt.setString(1,shopname);
  ResultSet rs=pstmt.executeQuery();
 
  


  if(rs.next()){
  out.print("有这个用户名了,请重新注册");
  }
  else
  {
  stmt =conn.createStatement();
  String sql ="insert into shop(shopname,price,number,brand,date) values ('"+shopname+"','"+price+"','"+number+"','"+brand+",'"+date+"');";
  stmt.executeUpdate(sql);
  out.print("商品添加成功,2秒钟后自动跳转");
  response.setHeader("Refresh","2;URL=admin/shop.jsp");
  stmt.close();
  }
  
 
  
  conn.close();
 }
 
catch(Exception e)
 {
 e.printStackTrace();
  out.println(e);
 }
    
    
  %>   





jsp报错 MySQL server version for the right syntax to use near 'null')' at line 1完整的报错是:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ve
最好是能够有代码行的错误信息,就是说明你哪行代码对应的SQL语句出的问题,这样更好分析.
根据代码,目测可能有以下问题:
1
pstmt=conn.prepareStatement("select username from user where username=?");
pstmt.setString(1,shopname);
这段中如果shopname是null的话执行结果可能有问题,所以最好先判断以下shopname是否非null.
2
String sql ="insert into shop(shopname,price,number,brand,date) values ('"+shopname+"','"+price+"','"+number+"','"+brand+",'"+date+"');";
这个段中是否都是字符型?,还有就是'"+brand+",少了一个引号