2010-06-21 13 views

उत्तर

19

खैर समाधान है कि मैं का उपयोग करें:

यह डीबी :)

+2

इस दृष्टिकोण के बारे में अधिक जानकारी के लिए, दस्तावेज़ देखें [INSERT कथन से चुनें] (http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2.doc.relg%2Finsl.htm) – Steven

+1

त्रासदी । वह "INSERT से चुनें" दस्तावेज़ या तो स्थान बदल गया है, या अनुपलब्ध हो गया है। – starlocke

+2

अपने डीबी 2 एसक्यूएल प्रोग्रामिंग गाइड में सम्मिलित मूल्य * डालने वाले अनुभागों का चयन करें। मेरे गाइड से एक उदाहरण है 'चयन EMPNO, HIRETYPE, HIREDATE से अंतिम टेबल (INSERT INTO EMPSAMP (नाम, वेतन, DEPTNO, स्तर) मूल्यों ('मैरी स्मिथ', 35000.00, 11, 'एसोसिएट'))' – Telemat

13
SELECT IDENTITY_VAL_LOCAL() AS VAL FROM SYSIBM.SYSDUMMY1 

docs देखें।

+0

SYSDUMMY1? मैं sysibm schema में उस तालिका को नहीं ढूंढ सकता ... :) –

+0

क्या आप विडंबनापूर्ण हैं? Http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0002369.html –

0

इस जवाब पर एक नज़र डालें में डाला अंतिम पंक्ति से आईडी स्तंभ हो जाता है।

http://www.sitepoint.com/php-database-db2/

// get the last inserted ID into the specified table 
// int lastInsertID(string $tblName) 
function lastInsertID($tblName) 
{ 
if ($this->transIsOpen()) 
{ 
    $sql = "SELECT SYSIBM.IDENTITY_VAL_LOCAL() AS id FROM " . $tblName; 
    $rs = $this->query($sql); 
    return $this->fetch($rs, "id"); 
} 
return -1; 
} 

या इस

http://www.php.net/manual/en/function.db2-last-insert-id.php#98361

0
int keyId = -1; 
preparedStatement.executeUpdate(); 
resultSet = preparedStatement.getGeneratedKeys(); 
if (resultSet.next()) { 
    keyId = rs.getInt(1); 
} 

https://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#getGeneratedKeys()

अद्यतन: और निम्नलिखित झंडासाथ preparedStatement बनाने के लिए मत भूलनाअन्यथा यह काम नहीं करेगा))

+0

उहम्म ... ओरेकल! = डीबी 2 – barrypicker

+0

जावा के लिए यह ट्यूटोरियल ओरेकल – Anatoly

+0

नहीं है तो आप ओपी के सवाल को संबोधित नहीं कर रहे हैं। – barrypicker

संबंधित मुद्दे