How to Pass the Checkbox Value Into Database Using JSP Servlet

Found This Helpful

The JSP language uses Java to insert data into a database using values inserted on the Web page. Your readers insert values, and the Java servlet code parses the data from the JSP form. It then inserts the data into a table. Create the SQL insert statement from the checkbox value, and use the database connection to insert the value into the table.


  1. Open your JSP editor and the Web project. Open the page that you want to use to retrieve the checkbox value and insert the value into the database.

  2. Create a variable and use the "getParameter" function to retrieve the checkbox value. The following code retrieves the value:

    string cbValue = req.getParameter("name");

    Replace "name" with the name of your checkbox on the JSP form.

  3. Connect to the database server. The following code uses a MySQL database example to connect to a database server:

    connection = DriverManager.getConnection (serverURL, "dbuser", "password");

    Replace the "serverURL," username and password with your database server information.

  4. Insert the checkbox value into a database table. The following code inserts the checkbox value into the "subscription" database:

    String query = "insert into subscript values (?)";
    PreparedStatement ps = connection.prepareStatement(query);
    int rows = ps.executeUpdate();



Read Article

8 iPhone Tips Everyone Should Know