I have a form and I want to send the data to a database. How can I pass the request data through the method parameters and send it to the Database?
int status = InsertCustomer(fName, mName, lName , iage, issn, city, state, country);
//Method // This method should return an int that the executeUpdate // methods returns. Note: the driver name and the URL are // already available in the init() method.
private int InsertCustomer(String firstName, String midName, String lastName, int age, int ssn, String city, String state, String country) {
// JDBC logic
try {
Class.forName(driverName);
Connection conn = DriverManager.getConnection(databaseURL);
java.sql.Statement st = conn.createStatement();
st.executeUpdate("INSERT INTO Customer(firstName, midName, lastName, age, ssn, city, state, country)" +
"VALUES ('?', '?', '?', ?, ?, '?', '?', '?')";
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return 1;
}
I'm a lil bit lost, a little would be very much appreciated.