Jdbc uses the merge into function in oracle
Merge into can merge data already in the oracle data table. If there is, update, otherwise update
The following example passes the test after the jdbc data source is connected
1. Single data
Long companyAuthId = SeqkeyUtil.getSeqKey (vids, "COMPANY_AUTH_ID"); CompanyAuth comtmp = companyList.get (0); String sql = "merge into COMPANY_AUTH auth using (select? MOBILE from dual) tmp on (auth.mobile=tmp.mobile)" + "WHEN MATCHED THEN" + "UPDATE SET auth.reserve=?" + "WHEN NOT MATCHED THEN" + "INSERT (id,MOBILE) VALUES"; vids.update (sql, new Object [] {comtmp.getMobile (), comtmp.getReserve (), companyAuthId+ ", comtmp.getMobile ()})
2. Multiple pieces of data (batch processing)
Long companyAuthId = SeqkeyUtil.getSeqKey (vids, "COMPANY_AUTH_ID"); / / seqs table primary key uses List batch = new ArrayList (); for (CompanyAuth company: companyList) {Object [] values = new Object [] {company.getMobile (), company.getReserve (), companyAuthId+ ", company.getMobile ()}; batch.add (values);} String sql =" merge into COMPANY_AUTH auth using (select? MOBILE from dual) tmp on (auth.mobile=tmp.mobile) "+" WHEN MATCHED THEN "+" UPDATE SET auth.reserve=? "+" WHEN NOT MATCHED THEN "+" INSERT (id,MOBILE) VALUES "; vids.batchUpdate (sql, batch)
If more than one table appears, you only need to target using (select? MOBILE from dual) tmp on can be modified.