jsp报错 MySQL server version for the right syntax to use near
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/23 10:47:59
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);
}
%>
完整的报错是:
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);
}
%>
最好是能够有代码行的错误信息,就是说明你哪行代码对应的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+",少了一个引号
根据代码,目测可能有以下问题:
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+",少了一个引号
check the manual that corresponds to your MySQL server versi
MySQL Error Message:Can not connect to MySQL server
Can not connect to MySQL server是什么意思
英语翻译Warning:mysql_connect():Lost connection to MySQL server
Can not connect to MySQL server这是什么意思?
$halt && $this->halt('Can not connect to MySQL server');这句是什
JSP错误:The server encountered an internal error () that preve
Thank you for comes Look to me near the door Turn right on t
MySQL Error:You have an error in your SQL syntax; check the
MySql报错:You can't specify target table 'table name' for upda
我每次开机用navicat打开MySQL都出现错误:2003-can't connect to mysql server
Fight For Your Right (Album Version) 歌词