automatic increment for field

This is a discussion on automatic increment for field within the Oracle Errors forums in Oracle Database category; hi to all i am new to this forum . i want to automatical increment for serial number in the table . i am create table ,sequence for that table and trigger for that . create table test (id number, testdata varchar2(255)); create sequence test_seq start with 1 increment by 1 nomaxvalue; create trigger test_trigger before insert on test for each row begin select test_seq.nextval into :new.id from dual; end; after creating this i am inserting values to this table from action class in struts but i am able to insert all values but i am not getting that how ...

Go Back   Database Forum > Oracle Database > Oracle Errors

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 03-25-2008, 05:38 AM
Default automatic increment for field

hi to all


i am new to this forum . i want to automatical increment for serial number in the table . i am create table ,sequence for that table and trigger for that .


create table test (id number, testdata varchar2(255));

create sequence test_seq
start with 1
increment by 1
nomaxvalue;

create trigger test_trigger
before insert on test
for each row
begin
select test_seq.nextval into :new.id from dual;
end;

after creating this i am inserting values to this table from action class in struts but i am able to insert all values but i am not getting that how to insert this test_seq.nextval in the table.

PreparedStatement stmt = Database.create().prepareStatement("INSERT INTO admininsertbook(sno,bookname,author,available) VALUES (?,?,?,?) ");
for(int i=0; i< arrayList.size(); i++){

stmt.setInt(1, Database.getNextVal());
stmt.setString(2, (String)arrayList.get(0));
stmt.setString(3, (String)arrayList.get(1))
stmt.setString(4, (String)arrayList.get(2))
stmt.addBatch();

}
stmt.executeBatch();
Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 11:57 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.