xiuxiumomo 2016-03-17 03:13 采纳率: 50%
浏览 1271

jsp老是提示没有使用?的权限

<%

String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPassword="123";
String dbName="test";
String url1="jdbc:mysql://localhost:3306/"+dbName;
String url2="?user="+userName+"&password="+userPassword;
String url3="&useUnicodetrue&characterEncoding=utf-8";
String url=url1+url2+url3;
Class.forName(driverName);
Connection conn=DriverManager.getConnection(url);
request.setCharacterEncoding("utf-8");
String sql="delete from taozi.student where age>=?";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,21);
int n=pstmt.executeUpdate(sql);
if(n>=1){%>success!<%}
else{%>failes!<%}
if(pstmt!=null){pstmt.close();}
if(conn!=null){conn.close();}

%>

就是修改的时候一直显示 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 '?' at line 1

  • 写回答

2条回答

  • ai2018 2016-03-17 04:59
    关注

    问题出在

    int n=pstmt.executeUpdate(sql);
    
    

    改成

    int n=pstmt.executeUpdate();
    
    

    就可以了,因为你使用了PreparedStatement ,而你在真正执行sql的时候,使用了占位符解析之前的sql。

    评论

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误