0

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>
3
Contributors
2
Replies
12
Views
4 Years
Discussion Span
Last Post by peter_budo
0

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.

Edited by LastMitch: grammer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.