Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

insert autoincremented value in db...

Thread view: 
gbattine - 03 Jul 2006 12:00 GMT
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...
Dag Sunde - 03 Jul 2006 12:21 GMT
> Hi guys,
> i'm a question for you.
[quoted text clipped - 18 lines]
> 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();

Signature

Dag.

gbattine - 03 Jul 2006 12:30 GMT
Thanks very much Dag....
i've resolved my problem thanks to you....


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.