mysql - How to get sequence.nextval from SQL in JDBC? -


i have 5 tables use same sequence's next value. problem is, subsequent tables gets bigger value previous ones.

my code this:

string sql = "insert table1(id, name) values (id_seq.nextval, ?)";  ps.setstring(1, "bar");  ps.executeupdate();      sql = "insert table2(id, name) values (id_seq.nextval, ?)"; ps.setstring(1, "tar");  ps.executeupdate(); sql = "insert table3(id, name) values (id_seq.nextval, ?)"; ps.setstring(1, "par");  ps.executeupdate(); sql = "insert table4(id, name) values (id_seq.nextval, ?)"; ps.setstring(1, "car");  ps.executeupdate(); sql = "insert table5(id, name) values (id_seq.nextval, ?)"; ps.setstring(1, "rar");  ps.executeupdate(); 

my sequence this:

create sequence  "id_seq"  minvalue 1 maxvalue 9999999999 increment 1         start 10 cache 20 noorder  nocycle ; 

now when @ tables, table1's id 10, table2's id 11 , table3's id 12..... want tables' ids same. should do? thank in advance.

edit: had include more tables 2 have more general question

you can use id_seq.currval second table. reuse same id.

sql = "insert table2(id, name) values (id_seq.currval, ?)"; 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -