On clicking <button> btnSave on html page, saveRecords.jsp is invoked to save the multiple rows of HTML.
The Code in saveRecords.jsp is as follows.
try{
String[] table_id = request.getParameterValues("table_id");
String[] hall_name = request.getParameterValues("hall_name");
String[] hall_capacity = request.getParameterValues("hall_capacity");
Class.forName("com.mysql.jdbc.Driver"); // MySQL database connection
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/chbs?" + "user=root&password=");
PreparedStatement pst = conn.prepareStatement("INSERT INTO `halls`(`Hall_ID`, `Hall_Name`, `Capacity`) VALUES (?, ?, ?);");
pst.setString(1, table_id);
pst.setString(2, hall_name);
pst.setString(3, hall_capacity);
int rset = pst.executeUpdate();
}
However, PreparedStatement.setString() doesn't accept Array. Since, the HTML table is in one .jsp and the code to save the values of HTML rows in in saveRecords.jsp which is different, the HTML table values are not getting posted and the PreparedStatement.setString() is throwing error. What is the correct way to do this?