从嵌入式数据库中检索数据不会起作用

时间:2018-01-02 12:57:46

标签: java jsp servlets derby

我正在尝试将数据从我的注册页面保存到我的数据库,但是它的工作原理并没有。有没有人建议我如何解决它?

这是我的jsp页面表单。 我正在使用嵌入式德比数据库。 任何建议将不胜感激。

<form class="form-signin"  method="POST" action="newuserservlet">
    <input type="text" class="input-block-level"  name="firstName" placeholder="First Name">
    <input type="text" class="input-block-level"  name="lastName" placeholder="Last Name"> 
<button class="btn btn-large btn-primary" >Sign up</button>

这是我的servlet:

public class newuserservlet  extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String firstname = request.getParameter("firstName");
    String lastname = request.getParameter("lastName");

    try {
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        Connection dbConnection = null;
        String strUrl = "jdbc:derby:billsdb;create=true";
        dbConnection  = DriverManager.getConnection(strUrl);
        PreparedStatement stmt = dbConnection.prepareStatement("insert into USERDATA values(?,?)");
        stmt.setString(1, firstname);
        stmt.setString(2, lastname);
        int i = stmt.executeUpdate();
        if (i > 0) {
            out.println("You are successfully registered.....");
        }
    } catch (Exception ey) {
        System.out.println(ey);
    }
    out.close();
}

0 个答案:

没有答案