1
mirror of https://github.com/CarmJos/EasySQL.git synced 2026-06-04 07:18:23 +08:00

添加一个同步插入返回ID的方法

This commit is contained in:
2021-12-14 17:30:51 +08:00
parent 2d384bdd15
commit 22c067990b
+15 -2
View File
@@ -92,9 +92,22 @@ public class EasySQLDemo {
.setKeyIndex(1) // 设定自增主键的index,将会在后续返回自增主键
.execute((exception, action) -> {
// 处理异常
System.out.println(action);
System.out.println("#" + action.getShortID() + " -> " + action.getSQLContent());
exception.printStackTrace();
});
try {
Integer userID = sqlManager.createInsert("users")
.setColumnNames("username", "phone", "email", "registerTime")
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
.setKeyIndex(1) // 设定自增主键的index,将会在后续返回自增主键
.execute();
System.out.println("新用户的ID为 " + userID);
} catch (SQLException exception) {
exception.printStackTrace();
}
}
}