मैं जेडीबीसी बैच आवेषण का उपयोग करके कई रिकॉर्ड डाल रहा हूं। क्या प्रत्येक रिकॉर्ड के लिए जेनरेट की गई कुंजी प्राप्त करने का कोई तरीका है? क्या मैं बैच प्रविष्टियों के साथ 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 != null)
ps.close();
release(con);
}
उपयोग कर रहा हूँ मैं ps.getGeneratedKeys()
पाश अंदर के साथ ps.executeUpdate()
का उपयोग कर वांछित परिणाम प्राप्त करने की सोच रहा हूँ। कोई अन्य समाधान?
क्या आप अपने बैच आवेषण में अनुक्रमों का उपयोग करते हैं? – Rachcha
हां, छात्रसेक्यू तालिका के लिए अनुक्रम है। – atripathi