There's a error when I run this jsp file --> " pstmt.executeUpdate();".

"org.apache.jasper.JasperException: An exception occurred processing JSP page /TestAdd.jsp at line 39"

My code essentially have a text box for users to enter a value, and then the value is sent to the MySQL database.

Any help is appreciated ~

<body>
    <FORM action="Testadd.jsp" method="post">
    <table border="1">
    <tr>
    <td>Size</td>
    <td><input type='text' size=15 name='Size'></td>
    </tr>
    <td><input type='submit' name='btnSubmit' value='Submit'></td>
    </table>
    </FORM>

    <%
    //Register JDBC driver
    Class.forName("com.mysql.jdbc.Driver");
    //Define Connection URL
    String connURL = "jdbc:mysql://localhost/test?user=root&password=aap";
    //Establish connection to URL
    Connection conn =   DriverManager.getConnection(connURL); 
    // Create Connection object conn 
    //Statement stmt = conn.createStatement();

        String getsize = request.getParameter("Size");

        PreparedStatement pstmt;

        pstmt = conn.prepareStatement("INSERT INTO test_db (size) VALUES (?)");

        pstmt.setString(1,getsize);

        pstmt.executeUpdate();  


    %>
</body>
Member Avatar for LastMitch

My code essentially have a text box for users to enter a value, and then the value is sent to the MySQL database.

The code you provided is inconclusive meaning there's no way of knowing what is wrong. The reason is you are not very specific of this:

pstmt.executeUpdate();

Base on the code it might be a connecting issue or your query is not working.

If you can post a little more code then it would be helpful and also explain what you are doing.

Read this tutrial connection from JSP is just very-very-very old faashioned

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.