kuangshow0227
AwesomeOcean
采纳率0%
2016-03-30 03:05 阅读 1.4k

【Java】查询数据时报错,请各大神指点~(附源码)

10

请求流程:
1、访问SearchList.jsp时请求servlet:SearchById;
2、SearchById 的doPost方法访问showInfoDao.findModeResult(sql);
3、JdbcUtils中对sql进行数据库查询,并将查询结果返回,展示在SearchList.jsp页面;

在第3步,数据库连接成功,查询的时候出现了“com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;”
报错信息如下:

 doGet 请求
doPost请求
数据库连接成功!
com.mysql.jdbc.exceptions.jdbc4.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 'from??personinfo' at line 1

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)

    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1912)
    at com.bdwm.dao.ShowInfoDao.findModeResult(ShowInfoDao.java:18)
    at com.bdwm.servlet.SearchById.doPost(SearchById.java:71)
    at com.bdwm.servlet.SearchById.doGet(SearchById.java:49)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
[]
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

6条回答 默认 最新

  • danielinbiti danielinbiti 2016-03-30 03:12
     check the manual that corresponds to your MySQL server version for the right syntax to use near 'from??personinfo' at line 1
     这不提示很明显,是sql有问题吗,  from和personinfo中间两个??,看看是不是编码有问题了
     把那个sql拷贝出来,在记事本中粘贴一下,然后再从记事本中拷贝到代码中试试
    
    点赞 评论 复制链接分享
  • javaDesire javaDesire 2016-03-30 03:18

    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 'from??personinfo' at line 1

    点赞 评论 复制链接分享
  • qq_29829081 TOMSCUT 2016-03-30 03:19

    这是异常是因为SQL语句出错了。错误提示里面说:“from??personinfo”这个位置附近出错了。你注意两点:第一,看看SQL语句里面表的名称有没有输入错误;第二,如果是用字符串拼接的SQL语句,一定要注意两个字符串之间的
    ”空格“(比如sql1=“select * from student”; sql2="where id = 3"; sql = sql1 +sql2, 最终的sql语句就成了sql= "select * from studentwhere id = 3"。此时,student和where就成了一个单词,导致sql语句出错。因此,在拼接时给sql1最后,或者sql2之前加一个空格就好了,例如sql2="where id = 3"; sql = sql1 +sql2, 最终的sql语句就成了sql= "空格符select * from studentwhere id = 3")。
    希望能够帮到你!

    点赞 评论 复制链接分享
  • beijing20110905 微风吹过的夏天2016 2016-03-30 03:45

    SQL语句写的不对。断点调试。取到SQL语句的内容,放到mysql数据库验证下语句是否能正确执行。如果能正确执行,但在代码中报错,可以试着在语句末尾加空格或去掉别名。

    点赞 评论 复制链接分享
  • zhangjs712 zhangjs712 2016-03-30 05:50

    把SQL语句发出来,看下啊

    点赞 评论 复制链接分享
  • qq_20039385 qq_20039385 2016-03-31 14:35

    错误提示很明显的说:你的sql语法错吴,把sql贴错来看看。

    点赞 评论 复制链接分享

相关推荐