Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC/insert

 
ron ray chaudhuri
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
A.S.Kumar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic