org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO TAB_CUSTOMER_INFO_SYNC_VIP (id, code, name, company_site, industry, fax, mobile, address, branch_code, branch_name, belong_branch, belong_center, create_time,vip_create_time ) values (?,?,?,?,?,?,?,?,?,?,?,?,new Date(),?)]; nested exception is java.sql.BatchUpdateException: 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 “”Date(),null)”” at line 1 |
|
#1 |
插入语句如下:
/ 插入vip客户表 String insertCustomerVipSql = "INSERT INTO TAB_CUSTOMER_INFO_SYNC_VIP (id, code, name, company_site, " + "industry, fax, mobile, address, branch_code, branch_name, belong_branch, " + "belong_center, create_time,vip_create_time ) values (?,?,?,?,?,?,?,?,?,?,?,?,new Date(),?)"; List<Map<String, Object>> listToBatch = null; for (int x = 0, len = custs.size(); x < len; x++) { if (listToBatch == null) { listToBatch = new ArrayList<Map<String, Object>>(); } listToBatch.add(custs.get(x)); if (((x + 1) % Constant.FETCH_WB_BATCH_EXECUTE_COUNT == 0) || (x == len - 1)) { // 最多5000 提交一次 cusVipDao.batchToUpOrInsertCV(listToBatch, insertCustomerVipSql); listToBatch = null; } } Dao层的代码 @Repository("customerVipDao") public class CustomerVipDaoImpl extends YdmcpBaseSpringJdbc<CustomerVip> implements CustomerVipDao { public void batchToUpOrInsertCV(List<Map<String, Object>> listToBatch, String insertSql) throws Exception { int size = listToBatch.size();//13个 :size=13 Object[] insertObjects = new Object[size]; //经测试:cusVipList.size()=1 for (int i = 0; i < size; i++) { // 循环 objList <Object> CustomerVip cusVip=new CustomerVip(); String code=cusVip.getCode(); String name=cusVip.getName(); String company_site=cusVip.getCompany_site(); String industry=cusVip.getIndustry(); String fax=cusVip.getFax(); String mobile=cusVip.getMobile(); String address=cusVip.getAddress(); String branchCode=cusVip.getBranchCode(); String branchName=cusVip.getBranchName(); String belongBranch=cusVip.getBelongBranch(); String belongCenter=cusVip.getBelongCenter(); Date vipCreateTime=cusVip.getVipCreateTime(); // String primaryKey = StringUtils.getUUID();;//用UUID生成主键 String id=cusVip.getId();//即id // TODO obj.getXXX(); insertObjects[i] = new Object[] {id, code, name, company_site, industry, fax, mobile, address, branchCode, branchName, belongBranch, belongCenter, vipCreateTime}; } super.batchUpdateNotAutoCommit(insertSql, size, insertObjects); // 批量插入或更新 } } |
#25分 |
语法错误了。 right syntax to use near “”Date(),null)”” at line 1 这个 Date()数据多少, 再看看 null这个 对不
|
#310分 |
sql没有new date这种写法,这个是java的
+ “belong_center, create_time,vip_create_time ) values (?,?,?,?,?,?,?,?,?,?,?,?,new Date(),?)”; 改为: + “belong_center, create_time,vip_create_time ) values (?,?,?,?,?,?,?,?,?,?,?,?,”+new Date()+”,?)”; |
#45分 |
数据库是oracle的话直接sysdate替换new Date()
或者你在插入之前本地new个date然后用TODATE(你new的date,””yyyy-mm-dd””)替换 |