अगर मैं (SQL डेवलपर) मेरी Oracle ग्राहक से इसे चलाने यह SQL विवरण काम करता है पर चयन:सम्मिलित करें के बाद आईडी डाला हो रही है ... ओरेकल
insert into Person (Name) select 'Bob' from dual
यह भी काम करता है अगर मैं इसे वसंत JDBC के माध्यम से जारी, बिना का उपयोग कर एक KeyHolder:
final PreparedStatementCreator psc = new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con)
throws SQLException
{
return con.prepareStatement(
"insert into Person (Name) select 'Bob' from dual");
}
};
jdbcOperations.update(psc);
हालांकि मैं आदेश नव डाला पंक्ति की आईडी प्राप्त करने में एक keyholder उपयोग करने के लिए की जरूरत है। अगर मैं एक keyholder उपयोग करने के लिए ऊपर दिए गए कोड को बदलने के इस प्रकार है:
final KeyHolder keyHolder = new GeneratedKeyHolder();
final PreparedStatementCreator psc = new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con)
throws SQLException
{
return con.prepareStatement(
"insert into Person (Name) select 'Bob' from dual",
new String[] {"PersonID"});
}
};
jdbcOperations.update(psc, keyHolder);
... तो मैं इस त्रुटि मिलती है: अगर मैं बजाय एक सम्मिलित करना ... मान
Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:94)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:602)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:842)
at au.com.bisinfo.codecombo.logic.ImportServiceImpl.insertLoginRedirectRule(ImportServiceImpl.java:107)
at au.com.bisinfo.codecombo.logic.ImportServiceImpl.runImport(ImportServiceImpl.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy8.runImport(Unknown Source)
at au.com.bisinfo.codecombo.ui.Main.main(Main.java:39)
Caused by: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1008)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3530)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.springframework.jdbc.core.JdbcTemplate$3.doInPreparedStatement(JdbcTemplate.java:844)
at org.springframework.jdbc.core.JdbcTemplate$3.doInPreparedStatement(JdbcTemplate.java:1)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:586)
... 15 more
Fwiw, सब कुछ ठीक एक सम्मिलित की ... का चयन करें (हालांकि यह मेरी मदद नहीं करता है, के रूप में मैं चीजों का चयन करना): मैं उपयोग कर रहा हूँ
final KeyHolder keyHolder = new GeneratedKeyHolder();
final PreparedStatementCreator psc = new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con)
throws SQLException
{
return con.prepareStatement(
"insert into Person (Name) values ('Bob')",
new String[] {"PersonID"});
}
};
jdbcOperations.update(psc, keyHolder);
:
- स्प्रिंग JDBC 3.0.3.RELEASE
- JDBC ड्राइवर: ojdbc6.jar संस्करण 11.2.0.1.0
- आरडीबीएमएस: Oracle9i रिलीज 9.2.0.5.0 - उत्पादन
- कॉमन्स-DBCP 1,4
एनबी मेरे ऐप को डीबी-तटस्थ रहने के लिए मानक एसक्यूएल का उपयोग करने की आवश्यकता है, जो किसी भी ओरेकल-विशिष्ट एसक्यूएल को रद्द करता है (मैं वास्तविक जीवन में "दोहरी" से चयन नहीं करूँगा)।
किसी भी मदद के लिए धन्यवाद।
कि विधि तीन में से एक है कि उत्पन्न कुंजी लौट सकते हैं, अन्य है दो तैयारी कर रहे हैं (स्ट्रिंग, int []) और तैयारी स्टेमेंट (स्ट्रिंग, स्ट्रिंग [])। मैं उत्तरार्द्ध का उपयोग कर रहा हूं, जो ओरेकल ओरेकल के लिए सही है। फिर भी, मैं आपके सुझाव का प्रयास करूंगा और आपको बता दूंगा कि यह कैसा चल रहा है। –
@ एंड्रयू स्वान आप सही हैं। धन्यवाद! लेकिन मुझे बताएं आउटपुट –