首页 文章

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

提问于
浏览
0

我想使用 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)处org.apache.jasper.runtime.HttpJspBase.service在org.apache.jsp.Questions_jsp._jspService(Questions_jsp.java:198 SQL.Select.getRecentQuestions(Select.java:447))(HttpJspBase.java :111)在javax.servlet.http.HttpServlet.s org.apache上的org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)中的orvice(HttpServlet.java:790)org.apache.jache上的org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473) .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)atg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)org.apache.catalina.core.StandardPipeline . 在org.apache的com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)的org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)上的doInvoke(StandardPipeline.java:734)位于org.apache.catalina.connector.Coyot的org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)的.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) eAdapter.service(CoyoteAdapter.java:283)位于com.sun.enterprise.v3.services.impl.ContainerMapper $ HttpHandlerCallable.call(ContainerMapper.java:459)的com.sun.enterprise.v3.services.impl.ContainerMapper . 在org.glassfish.grizzly.http.server.HttpHandler.runService服务(ContainerMapper.java:167)(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 . DefaultgilterChain.executeFilter(DefaultFilterChain.java:283)org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)at org org.glassfish.grizzly.Process中的.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111) orex.gailfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)orO.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)上的orExecutor.execute(ProcessorExecutor.java:77)在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 . 提前致谢 .

1 回答

  • 1

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

    也许你可以尝试 instrlike

相关问题