Xuanwomingren01 2017-01-16 06:11 采纳率: 61.1%
浏览 867
已采纳

谁能看下那里错了,sql问题

public List SerachLog(String module, String target, String method, String targetID, String eventType,
String eventLevel) {
// TODO Auto-generated method stub
List logs = new ArrayList();
try {
/**
* 拼接sql
*/

        String sqlStr3 = "select * from logs where 1 = 1";

        if (!"".equals(module) && module != null) {
            sqlStr3 += "and module='" + module + "' ";
        }
        if (!"".equals(target) && target != null) {
            sqlStr3 += "and target='" + target + "' ";
        }
        if (!"".equals(method) && method != null) {
            sqlStr3 += "and method='" + method + "' ";
        }
        if (!"".equals(targetID) && targetID != null) {
            sqlStr3 += "and targetID='" + targetID + "' ";
        }
        if (!"".equals(eventType) && eventType != null) {
            sqlStr3 += "and eventType='" + eventType + "' ";
        }
        if (!"".equals(eventLevel) && eventLevel != null) {
            sqlStr3 += "and eventLevel='" + eventLevel + "' ";
        }

        Connection con = JDBC.open();
        PreparedStatement ps = con.prepareStatement(sqlStr3);
        ResultSet rs = ps.executeQuery();//一会儿提示这里错误
        while (rs.next()) {
            Log log = new Log(rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getString(9),
                    rs.getString(10));
            logs.add(log);//一会儿又说这里错了
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return logs;
}
----------------------------------------------------------
错误提示
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 'module='n'' 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:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)
at cn.kerui.adapter.DBAdapter.SerachLog(DBAdapter.java:125)
at cn.kerui.test.Test1.main(Test1.java:49)
----------------------------------------------
List<Log> Q = as.SerachLog("n", null, null, null, null, null);
    System.out.println(Q.size());
    测试语句
  • 写回答

7条回答

  • haikuokuangtu 2017-01-16 06:18
    关注

    首先不知道你的1=1是干什么的,其次每一个and前面要有空格

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作