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());
测试语句