Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

prepared statement

Status
Not open for further replies.

sensory21

Programmer
Joined
Jan 27, 2004
Messages
79
Location
GB
Hi all,

//These are values entered in a form
String title = request.getParameter("title");
String firstname = request.getParameter("firstname");
String lastname = request.getParameter("lastname");

//The primary key is set up as auto_increment in the db
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO staff VALUES(NULL,?,?,?)");
pstmt.executeUpdate();

I get this error when compiling:
"No value specified for parameter 1" ?

how do you set that the first question mark is title etc...

cheers
vero
 
pstmt.setString(1,title);
pstmt.setString(2,firstname);
etc...
 
Hi

//The primary key is set up as auto_increment in the db
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO staff VALUES(NULL,?,?,?)");
pstmt.setString(1,title);
pstmt.setString(2,firstName);
pstmt.setString(3,lastName);
pstmt.executeUpdate();

SQL Qry can also be written as the one below

INSERT INTO STAFF (title,firstName,lastName) VALUES (?,?,?);

Where in you can see the 1 = title, 2=firstName etc.

Hope this will help you..

Cheers
Venu
 
Thank you Venu and Idarke it's fine now. x
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top