java.sql.SQLException:几何字节字符串必须是小端

时间:2018-02-25 13:40:56

标签: java mysql sql prepared-statement sqlexception

我想使用contains函数获取titlequestion包含特定值的所有值。但是,我收到了这个错误:

  

java.sql.SQLException:几何字节字符串必须是小端。         在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)         在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)         在com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:2076)         在com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1932)         在com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:3426)         在com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:488)         在com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:3131)         在com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2299)         在com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2722)         在com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2794)         在com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)         在com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)         在SQL.Select.getRecentQuestions(Select.java:447)         在org.apache.jsp.Questions_jsp._jspService(Questions_jsp.java:198)         在org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)         在javax.servlet.http.HttpServlet.service(HttpServlet.java:790)         在org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)         在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)         在javax.servlet.http.HttpServlet.service(HttpServlet.java:790)         在org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)         在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)         在org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)         在org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)         在com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)         在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)         在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)         在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)         at com.sun.enterprise.v3.services.impl.ContainerMapper $ HttpHandlerCallable.call(ContainerMapper.java:459)         at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)         在org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)         在org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)         在org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)         在org.glassfish.grizzly.filterchain.ExecutorResolver $ 9.execute(ExecutorResolver.java:119)         在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)         在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)         在org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)         在org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)         在org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)         在org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)         在org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)         在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)         在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access $ 100(WorkerThreadIOStrategy.java:56)         在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy $ WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)         在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:591)         在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:571)         在java.lang.Thread.run(Thread.java:748)

这是代码:

public String getRecentQuestions(String search) throws SQLException {
        PreparedStatement ps=con.prepareStatement("select title, question_id from questions where contains(title, ?) or contains(question, ?) limit 20");
        ps.setString(1, search);
        ps.setString(2, search);
        ResultSet rs=ps.executeQuery();
        StringBuilder sb=new StringBuilder("");
        while (rs.next()) {
            sb.append("<a href='Question.jsp?question=").append(rs.getInt(2)).append("'><h2>");
            sb.append(rs.getString(1));
            sb.append("</h2></a>");
        }
        return sb.toString();
    }

我的PreparedStatement有效,title列数据类型为varcharquestion列数据类型也为varchar。 提前谢谢。

2 个答案:

答案 0 :(得分:2)

mysql使用 instr(str,substr)而不是包含

也许你可以尝试 instr 喜欢

答案 1 :(得分:0)

肖恩·许是对的。 您可以使用“ INSTR(str,substr)”对文本进行模糊查询。 例如:其中INSTR(content,“ test”)> 0 , “ INSTR”比“ like”更有效