pls Help

  • Thread starter Chowdhury, Ziaul
  • Start date
C

Chowdhury, Ziaul

Hi

Question is how to use SEQUENCE in PrepareStatement

My code is as follows but not working

public void addBook() {
PreparedStatement ps = null;
try {
//initiating Prepare Statement
ps = conn.prepareStatement("INSERT INTO Books (bookno, name, " +
"author, genre, cost) VALUES(bookitm_seq.nextval, ?, ?, ?, ?)");
//bookitm_seq.nextval;
//inserting Data
//ps.setInt(1, 50);
ps.setString(2, BookName);
ps.setString(3, Author);
ps.setInt(4, Genre);
ps.setDouble(5, Cost);
ps.executeUpdate();

If I am using ps.setInt(1, 50) then it is wokring fine. But I need use
Squence which has created with table name bookitm_seq
 
L

Lee Fesperman

Question is how to use SEQUENCE in PrepareStatement

My code is as follows but not working

public void addBook() {
PreparedStatement ps = null;
try {
//initiating Prepare Statement
ps = conn.prepareStatement("INSERT INTO Books (bookno, name, " +
"author, genre, cost) VALUES(bookitm_seq.nextval, ?, ?, ?, ?)");
//bookitm_seq.nextval;
//inserting Data
//ps.setInt(1, 50);
ps.setString(2, BookName);
ps.setString(3, Author);
ps.setInt(4, Genre);
ps.setDouble(5, Cost);
ps.executeUpdate();

If I am using ps.setInt(1, 50) then it is wokring fine. But I need use
Squence which has created with table name bookitm_seq

You need to change your setXXX() parameter numbers (the numbers correspond to the ?'s in
the SQL command) ...

ps.setString(1, BookName)
ps.setString(2, Author)
...

Also, you need to follow Sun's conventions for variable names. Variable names should
start with a lowercase letter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top