我的JSP代码未在数据库中插入数据

时间:2019-05-02 17:39:43

标签: java html jsp jdbc backend

我正在使用JSP代码,想将我的页面与mysql数据库连接,并在数据库中插入名称和电子邮件,但不能,我想知道原因

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*, java.util.*"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP handle Page</title>
    </head>
    <body>
        <% 
            String first_name = request.getParameter("user");
            String email = request.getParameter("email");

try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/user","root","");
    Statement st=conn.createStatement();
    int i=st.executeUpdate("insert into info (name,email) values ('"+first_name+"','"+email+"')");
    if(i!=0)
    {
        System.out.println("Data inserted");
    }
    else 
    {System.out.println("no");}

}
catch (Exception e)
{
    e.printStackTrace();
}

        %>
    </body>
</html>

0 个答案:

没有答案