Java Servlet将字符串转换为Mysql文本

我正在尝试从用户那里获取文本。并将该文本添加到数据库。但是我做不到。一直将空值插入数据库。我的代码是:

HTML:

<form action="gorev" method="post">
<textarea id="gorev" rows="4" cols="50">

</textarea>
<input type="submit" value="ekle">
</form>

和SERVLET:

    String gorev = request.getParameter("gorev");

    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con= (Connection) 


  DriverManager.getConnection("jdbc:mysql://localhost:3306/covid","root","*");


                 PreparedStatement pst = (PreparedStatement) con.prepareStatement(" insert into gorevler(gorevtext) values(?)");
                 pst.setString(1, gorev);
                 pst.executeUpdate();
                 response.sendRedirect("gorevler.jsp"); 
评论
  • 微笑暂离
    微笑暂离 回复

    更换

    <textarea id="gorev" rows="4" cols="50">
    

    <textarea name="gorev" id="gorev" rows="4" cols="50">