Java 如何基于2个键创建JDBC upsert查询

Java 如何基于2个键创建JDBC upsert查询,java,sql,jdbc,upsert,Java,Sql,Jdbc,Upsert,我想基于2列预插入(更新或创建): 如果表中存在A列和B列,则更新值,否则使用此键创建新行 //pasdo code for my query if(table.key1 == firstKey && table.key2 == secKey){ //update values for the row with key1, key2 } else { //create a row with firstKey, secKey as keys } 我的后端有一个oracle sq

我想基于2列预插入(更新或创建): 如果表中存在A列和B列,则更新值,否则使用此键创建新行

//pasdo code for my query
if(table.key1 == firstKey && table.key2 == secKey){
 //update values for the row with key1, key2
} else {
//create a row with firstKey, secKey as keys
}

我的后端有一个oracle sql server。

您可以执行类似的操作。。。 在oracle中,dual类似于虚拟表。它没有任何行。。它有助于创建合并查询所需的临时表 以下可能不完全是SQL语法

merge into table m using (select firstKey,secKey from dual d) on 
(m.key1 = d.firstKey and m.key2 = d.secKey )
         when not matched then insert... -- put insert statement here
             when matched then update .. -- put statemenet here

所以问题是…如何创建这样的查询…只要用谷歌搜索更新和插入查询,你就会得到很多例子。我做了,但仍然没有找到缺少的部分-基于2列。你可能正在寻找。