• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JDBC/insert

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just a basic question really:

I'm trying to insert a record into a table which has an auto-generated primary key.
I insert values in all the columns except the primary key, but I get the following error:

java.sql.SQLException: Missing IN or OUT parameter at index:: 1
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
at oracle.jdbc.driver.OracleStatement.checkBindsInAndOut(OracleStatement.java:1323)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1842)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:363)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:407)
at com.ibm.ejs.cm.cache.CachedStatement.execute(CachedStatement.java:480)
at com.ibm.ejs.cm.proxy.StatementProxy.executeCommon(StatementProxy.java:226)
at com.ibm.ejs.cm.proxy.PreparedStatementProxy.execute(PreparedStatementProxy.java:42)
at com.abnamro.portal.ods.OdsService.saveConfirmedRFQData(OdsService.java:1493)
at com.abnamro.woca.portal.fx.rfq.audit.Audit.doAuditResponse(Audit.java:197)
at com.abnamro.woca.portal.fx.rfq.RFQService.onRFQResponse(RFQService.java:450)
at com.abnamro.woca.portal.fx.rfq.RFQResponseHandler.run(RFQResponseHandler.java:49)
at java.lang.Thread.run(Thread.java:512)

Can anybody please help?

Cheers,
Ron
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Get the primary key value first ( it is a sequence number right )
then pass that value to in parameter...

Regards,

A.S.Kumar
 
ron ray chaudhuri
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Do you mean access the primary key from the sequence directly or get the Max value in the primary Key column , increment it by 1 and then insert it?

The latter kind of defeats the purpose of using a sequqnce doesn't it? if you mean the former, how can I accessthe sequence through Java?

Thanks in advance,
Ron
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the stacktrace I see you're using Oracle, correct? You can grab the next sequence value using a simple select statement:In Oracle, dual is a special psuedo-table containing a single row allowing for these kinds of tricks.

It also looks like you're using a PreparedStatement. Do you have a ? placeholder for the primary key? If so, you must supply a value. Or, are you registering it as an OUT parameter? If the latter, I'm not aware that Oracle will send it back to you automatically.

In fact, I'm not aware of Oracle having any kind of auto-generated primary key mechanism, though perhaps you can set the default for the column as the sequence's next value. Since my apps have always needed to access the row being inserted after insertion, I always grab the sequence value and then use it in the insert as A. S. Kumar suggested.
[ January 25, 2005: Message edited by: David Harkness ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic