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);
}
%>