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 链接问题 C++LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接