如何从jsp中检索数据并存储在数据库中?

时间:2017-01-27 07:47:33

标签: html sql database jsp

我想从html页面获取数据并在jsp页面中使用这些值并将这些值存储在数据库中。你能帮忙吗?

我的html页面:

<html>
<head>
    <title>reading values</title>
</head>
<body>
<form action="click.jsp">name:
    <input type="text" name="name" value=""/><br/> <br/>
    <button type="submit" name="submit" value="submit">submit</button>
    <button type="reset" name="reset" value="reset">reset</button>
</form>
</body>
</html>

我的jsp页面:

<html>
<head>
    <title>Click.jsp</title>
</head>
<body>
<%
    Connection conn=null;
    String u=null;
    u=request.getParameter("name");
    Class.forName("org.apache.derby.jdbc.ClientDriver");
    connection=DriverManager.getConnection("jdbc:derby://localhost:1527/***", "admin", "*****");
    Statement stmt=connection.createStatement();
    String sql= "INSERT INTO (table name) VALUES (?)";
    PreparedStatement prep = connection.prepareStatement(sql);
    prep.setString(1,u);
    prep.executeUpdate();

    prep.close();
    stmt.executeUpdate(sql);
%>
</body>
</html>

0 个答案:

没有答案