2012-11-26 168 views

回答

2

請參考您的問題我相信您正在使用的語句。在這種情況下,您可以使用Statement.RETURN_GENERATED_KEYS。下面的解決方案也可以考慮這個link對Oracle數據庫有所疑問。

下面是小例子:在你的情況下

Connection connection = database.getConnection(); 
PreparedStatement statement = connection.prepareStatement(myQuery, Statement.RETURN_GENERATED_KEYS); 
int count = statement.executeUpdate(); 
if(count <= 0){ 
//value not inserted 
} 

ResultSet results = statement.getGeneratedKeys(); 

if(results.next){ 
System.out.println(generatedKeys.getLong(1)); 
} 

使用ORM:

如果你正在使用JPA entitiyManager.merge(entity);(或更新)應與ID返回持久化實例。 與休眠很相似session.merge(entity);(或更新)

1

不知道它是如何與java/jsp,但如果它是一個關係數據庫,你將不得不使用一組查詢 - 即得到你知道的一個id(cid),然後從書中擺脫表。我沒有其他方式知道。

希望有所幫助。

相關問題