Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


jdbc prepared statement :oracle sequence

Posted on 1999-06-22
Medium Priority
Last Modified: 2008-03-04
I am using a JDBC Prepared Statement to insert data into a table. I want to insert a sequnece value for a unique id using seq_tablename.nextval.
But it is taking this as a string and throwing an sql exception.
I tried by retrieving seq_tablename.nextval prior to the insertion only to face the following error:
ORA-01006 bind variable does not exist.
Help appreciated
Question by:maggari
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1086986
I'm sure JAVA experts will give you a straight answer. But, here are two workarounds:
- Instead of using insert in your JAVA program, write a stored procedure which will get the sequence value and use it for the inserted record
- write a BEFORE INSERT trigger that will use the sequence to assign the value to the inserted record's PK

Author Comment

ID: 1086987
In fact, I used a trigger and it worked fine. But I don't want to use a trigger.

Accepted Solution

gizmola earned 0 total points
ID: 1086988
Selecting from a sequence is no different than any other type of query, other than you need to specify the magic DUAL table, ala select seq_tablename.nextval from dual

I'm not java proficient, but figured you are already finding a way to bind result sets to variables at this point, and this issue would explain your problem.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question