首页 > 解决方案 > 如何使用 servlet 在 mysql 数据库中插入全名?例如 - viraj sharma

问题描述

我的代码是

 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
   PrintWriter out = resp.getWriter();
   try {

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/patient", "root", "");
    PreparedStatement ps = con.prepareStatement("insert into userdetails(userType) VALUES(?)");
    ps.setString(1, req.getParameter("userType"));

    int b = ps.executeUpdate();
    if (b > 0)
     out.print("succes");
    else
     out.print("fail");
   }

当我运行这个程序时,它只插入全名的名字,即viraj 我想存储viraj Sharma.

标签: javamysqljspservlets

解决方案


推荐阅读