com.microsoft.sqlserver.jdbc.SQLServerException: '=' 附近有语法错误。求大神指点迷津!

qq_27784145 qq_27784145 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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;
}
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
qq_27784145
Web 开发 81,108 成员 341,721 内容