java - 如何获取我刚刚插入数据库的自动生成的 ID (Java)
问题描述
我知道有类似的问题,但我在 java 中找不到它,这是我的问题,我有一个名为“transactions”的表,它有一个自动生成的 Id [COT_Id],我有一个中间表 [USER_TRANS],其中包含以下列:[ COT_Id], [USER_Id] 在事务表和用户表之间建立关系,我需要在事务中插入一个新值,它已经完成,现在一旦插入,我需要获取自动生成的 ID 以便将其插入中间表中,这是我的代码:
Transaction transaccion = new Transaction();
transaccion.setMvg_id(mvg_id);
aproCvv = generalService.getCardByCvv(cvv, cardNum);
transaccion.setCrd_id(aproCvv);
transaccion.setCot_amount(cot_amount);
transaccion.setCot_cuotas(cuotas);
transaccion.setCcr_id(ccr_id);
transaccion.setCot_authorizationNumber(numeroauto);
Date dateAct = new Date();
transaccion.setCot_CreateDate(dateAct);
transaccion.setEsb_id(esb_id);
transaccion.setCot_Ip(ipRemoto);
transaccion.setCot_cashUser(cot_cashUser);
transaccion.setCot_Reference(cot_Reference);
transaccion.setChn_id(chn_id);
transaccion.setCot_reverseReference("5454");
transaccion.setCot_transactionPin("566546df");
transaccion.setTrs_id(54);
if(resultado) {
transactionService.saveTrans(transaccion);
//here's where I need the autogenerated Id (transId)
generalService.saveUserTrans(udID, transId, 1);
解决方案
推荐阅读
- r - 具有 3 个滞后的第一个差分记录预测序列的逆差分
- vba - “自上次……”VBA PowerPoint 幻灯片更新
- javascript - 当 $(document).ready() 中的代码运行时,我们可以指望我们所有的 Angular 组件都在那里吗?
- logstash - 如何实现 Logstash 过滤器来处理不同的日志文件格式/类型
- vb.net - 从excel中读取列并从最高到最低列出?
- reactjs - 错误:只能在函数组件的主体内部调用挂钩
- machine-learning - 大型网格世界环境的 DQN 探索策略
- mysql - 将 MySQL 表中的分区添加到已经分区的表中
- c - 改进的幂递归函数
- python - 如何在极坐标图中用平滑线连接点?