相关疑难解决方法(0)

来自sql insert的身份通过jdbctemplate

是否可以在Spring jdbc模板调用中从SQL插入中获取@@ identity?如果是这样,怎么样?

java sql-server spring jdbc jdbctemplate

54
推荐指数
3
解决办法
5万
查看次数

如何从Oracle中的JDBC批量插入中获取生成的密钥?

我使用JDBC批量插入插入许多记录.有没有办法获得每条记录的生成密钥?我可以使用ps.getGeneratedKeys()批量插入吗?

我在用 oracle.jdbc.OracleDriver

final String insert = "Insert into Student(RollNumber, Name, Age) values(StudentSEQ.nextval, ? , ?)";
final int BATCH_SIZE = 998;
int count = 0;
Connection con = null;
PreparedStatement ps =  null;
try {
    con = getConnection();
    ps = con.prepareStatement(insert);
    for (Student s : students) {
        ps.setString(1, s.getName());
        ps.setInt(2, s.getAge());
        ps.addBatch();
        count++;
        if (count % BATCH_SIZE == 0) {
        // Insert records in batches
            ps.executeBatch();
        }
    }
    // Insert remaining records
    ps.executeBatch();
} finally {
    if(ps != …
Run Code Online (Sandbox Code Playgroud)

java oracle jdbc primary-key batch-insert

10
推荐指数
2
解决办法
1万
查看次数