catch(SQLException e){ e.printStackTrace(); out.print("购买失败"); } 报错内容 :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 'order(username,movie_name,time,price,number) values ('sky','movie_name','11:00:0' at line 1
String username=request.getParameter("username");
String movie_name=("movie_name");
String time=request.getParameter("time");
String price=request.getParameter("price");
String number=request.getParameter("BuyNumber");Connection conn;
PreparedStatement pstmt=null;
try{
Class.forName(driverClass).newInstance();
conn=DriverManager.getConnection(url,user,password);
String sql="insert into order values (?,?,?,?,?)";
pstmt=conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pstmt.setString(1,username);
pstmt.setString(2,movie_name);
pstmt.setString(3,time);
pstmt.setString(4,price);
pstmt.setString(5,number);
pstmt.executeUpdate();
out.print("购买成功");
}
catch(SQLException e){
e.printStackTrace();
out.print("购买失败");
}
pstmt=conn.prepareStatement(sql);
Class.forName(driverClass).newInstance();
conn=DriverManager.getConnection(url,user,password);
String sql="insert into order ('sky','movie_name','19:00:00','50','1') values (?,?,?,?,?)";
pstmt=conn.prepareStatement(sql); pstmt.executeUpdate();
out.print("购买成功");
}
catch(SQLException e){
e.printStackTrace();
out.print("购买失败");
}这样还是会报错:java.sql.SQLException: No value specified for parameter 1。
求教
valuse 前面写字段名,你这看起来像是数据
perstmt.setString(1,var1);
perstmt.setString(2,var2);
perstmt.setString(3,var3);
perstmt.setString(4,var4);
perstmt.executeUpdate();
Connection conn;
PreparedStatement pstmt=null;
try{
Class.forName(driverClass).newInstance();
conn=DriverManager.getConnection(url,user,password);
String sql="insert into order(username,movie_name,time,price,number) values (?,?,?,?,?)";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,username);
pstmt.setString(2,movie_name);
pstmt.setString(3,time);
pstmt.setString(4,price);
pstmt.setString(5,number);
pstmt.executeUpdate();
out.print("购买成功");
}
catch(SQLException e){
e.printStackTrace();
out.print("购买失败");
} 报错内容 :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 'order(username,movie_name,time,price,number) values ('sky','movie_name','11:00:0' at line 1
order是关键字 不能作为表名 列名
所以出错了
好像是sql语句解码的问题,总感觉是跳过了try中的语句,有什么好的建议吗