insert autoincremented value in db...

G

gbattine

Hi guys,
i'm a question for you.
My jsf application receive in input a file,store it into an array of
byte and put it into a table tbl of a mysql db.
The table has 2 field

Nome=Int autoincrement
Data=LongBlob

When i use

Connection db=dbs.getConnection();
PreparedStatement pst = db.prepareStatement("INSERT INTO tbl(Nome,Data)
VALUES (?,?)");
pst.setInt(1,*); what have i to put for *???????????
pst.setBytes(2, data);
pst.executeUpdate();
pst.close();

I read from teory i have to pass null for autoincremented value but my
compiler expects an it for setInt(Int,Int).
How can i do?
Thanks...
 
D

Dag Sunde

gbattine said:
Hi guys,
i'm a question for you.
My jsf application receive in input a file,store it into an array of
byte and put it into a table tbl of a mysql db.
The table has 2 field

Nome=Int autoincrement
Data=LongBlob

When i use

Connection db=dbs.getConnection();
PreparedStatement pst = db.prepareStatement("INSERT INTO
tbl(Nome,Data) VALUES (?,?)");
pst.setInt(1,*); what have i to put for *???????????
pst.setBytes(2, data);
pst.executeUpdate();
pst.close();

I read from teory i have to pass null for autoincremented value but my
compiler expects an it for setInt(Int,Int).
How can i do?

You ignore the autoinc column in code when inserting.
You have already told the db to handle that.

Change the above to something like:

Connection db=dbs.getConnection();
PreparedStatement pst = db.prepareStatement("INSERT INTO
tbl(Data) VALUES (?)");
pst.setBytes(1, data);
pst.executeUpdate();
pst.close();
 

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,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top