81,122
社区成员




public class WorkDAOImpl implements WorkDAO {
protected Connection con; //数据库连接
protected PreparedStatement pre; //实例
protected ResultSet res; //结果集
public List<CustomerInfo> getAllList( int addTime ) {
List<CustomerInfo> list = new ArrayList<CustomerInfo>();
con = DBCon.getConnection();
try {
String sql="select a.* , b.condition_name from customer_info a ,customer_condition b " +
"where a.condition_id=b.condition_id and a.is_used='1' ";
if(addTime == 0 ){
sql += " select datediff(day,birth_day,getDate())=0";
} else if(addTime != 0 ){
sql += " select datediff(day,birth_day,getDate())>=0 and datediff(day,birth_day,getDate())<='"+addTime+"' ";
}
pre = con.prepareStatement(sql);
res = pre.executeQuery(); //报错内容中提到这行 也不知道为什么
while (res.next()) {
CustomerInfo customerInfo = new CustomerInfo();
customerInfo.setCustomerId(res.getInt("customer_id"));
customerInfo.setCustomerName(res.getString("customer_name"));
customerInfo.setCustomerBirthday(res.getString("birth_day"));
customerInfo.setCustomerMobile(res.getString("customer_mobile"));
customerInfo.setConditionId(res.getInt("condition_id"));
customerInfo.setCustomerCondition(res.getString("condition_name"));
customerInfo.setIsUsed(res.getString("is_used"));
list.add(customerInfo);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
DBCon.closeAll(con,pre,res);
}
return list;
}
com.microsoft.sqlserver.jdbc.SQLServerException: '=' 附近有语法错误。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:404)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:285)
at com.sxxy.dao.impl.WorkDAOImpl.getLinkMan(WorkDAOImpl.java:89)
at com.sxxy.service.impl.WorkServiceImpl.getLinkMan(WorkServiceImpl.java:29)
at com.sxxy.servlet.work.WorkQueryServlet.doGet(WorkQueryServlet.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1703)
at java.lang.Thread.run(Thread.java:722)
系统报如上的错误 可以运行程序 但是有错