i have a table where data is entered using a form.there is an id field which has to take values automatically i.e increament the field value as other fields are entered. pls can any one help me.
i have a table which has 5 fields one of them is integer(id) .i wanted to assign values to it automatically in sequence using java as i'm entering other values using sql query in java
PreparedStatement st=con.prepareStatement("insert into spotlight(ID IN SEQUENCE,req_name,req_desc,status,start_date) values(?,?,?,?) ");
I've re-read your posts: you are not actually using a sequence are you? Be careful before you rush to answer that - "sequence" (in this context) is an Oracle/Postgres specific term, so if its not either you are using, then ignore my previous post. If however it is, the syntax for selecting the next value from a sequence is "select seq_name.nextval from dual"/"select nextval('sequence_name')" respecitively - not using the max() function. If you are using another RDBMS then you probably have an autonumber or serial datatype as Blake Minghelli points out. In which case, just leave the PK out of your insert statement and let the DB handle it. i.e.:
[ June 17, 2004: Message edited by: Paul Sturrock ]
jaya sudha
Greenhorn
Joined: Jun 18, 2004
Posts: 20
posted
0
Hai Everybody,
First create a sequence in the DB then use the sequence in the insert statment like this
st=con.prepareStatement("insert into table_name(req_id,req_name) values(?,?) ");
st.setInt(1,sequencename.nextval); st.setString(2,name); Pls try this [ June 18, 2004: Message edited by: jaya sudha ]
Sudha
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.