*
The moose likes JDBC and the fly likes Inserting values to oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Inserting values to oracle" Watch "Inserting values to oracle" New topic
Author

Inserting values to oracle

Megha Rajeevan
Greenhorn

Joined: Mar 22, 2006
Posts: 24
Hello Ranchers,
I'm doing a program in JSP and Oracle.. In that the oracle table details are here
------------------------------------------------------
column
------------------------------------------------------
reg_no
name
password
confirm
-------------------------------------------------------

in this table the reg_no is a primary key and there is a sequence
ie., the number starts with 1000 and increment by 1

now from the jsp page.. i want to insert a new user registation details..

at that time the query i;m using is
insert into table_name (reg_no,name,password,confirm)values (reg_no.nextval,name,password,confirm);

but it is not inserting and showing errors..
so what should i do to insert the values in to the table where there is a sequence and a primary key!!

please help me.. ranchers..
thanks in advance

regards

Megha Rajeev
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Originally posted by Megha Rajeevan:

but it is not inserting and showing errors..




What error does it show ??

Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Megha Rajeevan
Greenhorn

Joined: Mar 22, 2006
Posts: 24
hello Shalish..
Thanks for replying and sorry for the lack of information..
Actully it is showing the error.. invalid column name.
ie., reg_no.nextval is a invalid column name..

what should i do to insert the auto number..

please help me ranchers..

thanks in advance

regards
Megha
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Your syntax looks OK. Does the sequence reg_no exist and does your user have privileges to use it?

(BTW: when posting an exception message it is usually better to just cut and paste the message rather than posting what you think the message means. There is less scope for error that way)
[ May 23, 2006: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333


Actully it is showing the error.. invalid column name.
ie., reg_no.nextval is a invalid column name..


I very much doubt that (your interpretation, not the error message). You probably have an error elswhere in your SQL statement.

Let me guess; you're using Statement, instead of PreparedStatement, and dynamically building a String variable to hold your SQL?

Post some code and we'll see what's wrong.
Sunil Dumpala
Greenhorn

Joined: Jul 28, 2005
Posts: 29
Megha,

To check if the sequence you are using exists and working or not try to run the following query on oracle through sqlplus (or any query runner interface)

select reg_no.nextval from dual;

If this results in a number then we can look further.

Thanks,
Sunil
Megha Rajeevan
Greenhorn

Joined: Mar 22, 2006
Posts: 24
Thank u RancherS!!
Now the query is executing successfully..
I don't know what happened to it yesterday
when ever i try to insert the values it was inserting 2 times..
and when i restarted my system..
it is ok now

i think there is some problem with the system cache..

any way thank you very much
for your great support..

regards
Megha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inserting values to oracle
 
Similar Threads
Hibernate: Optimization: id generation & two step insert
inserting a sequence value to the table
getting Primary key when inserting
primary key field
TableGenerator