Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert row into database with PreparedStatement

Tags:

I want to insert a row into a table using PreparedStatement. The table got 3 columns(int, String, String). The thing is that the int column is AUTO_INCREMENT, so I want to leave that variable empty and let the database do that job (It's an id). Haven't found out how to do this though!

It's an MySQL database.

like image 258
Lucas Arrefelt Avatar asked Aug 04 '12 00:08

Lucas Arrefelt


1 Answers

That's relatively simple, just leave out the autoincrement column from the column list:

insert into mytbl(str1, str2) values (?, ?) 

Prepare the statement, set the two parameters, and execute in non query mode.

like image 153
Sergey Kalinichenko Avatar answered Oct 24 '22 04:10

Sergey Kalinichenko