Sunday, September 28, 2014

How to Pass the Checkbox Value Into Database Using JSP Servlet

Instructions

    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:

    Class.forName("org.gjt.mm.mysql.Driver");
    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();



No comments:

Post a Comment