Saturday, March 5, 2011

Java - Insert Statement - My SQL

String rollno = "1";
String name = "ABC";
Connection con = getConnection();

String query = "insert into student (rollno, name) values (?,?)";
/*student is the table name, rollno and name are the field names*/

PreparedStatement preparedStatement = con.prepareStatement(query);


*  String query = "insert into student (rollno, name) values ('1','ABC')";
*  PreparedStatement preparedStatement = con.prepareStatement(query);
*  NB: This is also correct. First format is used if the inputs are from user through JTextField.

int noOfRowsUpdated = preparedStatement.executeUpdate();


Post a Comment

Contact Form


Email *

Message *

The Insane Techie - Android App

Launched an android app for the blog on 07th June 2016. Get it from google play store... Tips for using the app Use in landscape mo...