wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes JDBC/insert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC/insert" Watch "JDBC/insert" New topic


ron ray chaudhuri

Joined: Aug 27, 2003
Posts: 7
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?


Joined: Jul 30, 2002
Posts: 1

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


ron ray chaudhuri

Joined: Aug 27, 2003
Posts: 7

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,
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
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 ]
I agree. Here's the link: http://aspose.com/file-tools
subject: JDBC/insert