问题描述
- Jsp无法向数据库添加除数字以外的字符
-
向数据库添加信息的代码为:byte b1[] = request.getParameter("name").getBytes("ISO-8859-1"); String na = new String(b1); byte b2[] = request.getParameter("email").getBytes("ISO-8859-1"); String em = new String(b2); byte b3[] = request.getParameter("title").getBytes("ISO-8859-1"); String ti = new String(b3); byte b4[] = request.getParameter("content").getBytes("ISO-8859-1"); String co = new String(b4); if (na == null) na = ""; if (ti == null) ti = ""; if (co == null) co = ""; if (em == null) em = ""; try { // 将获得的留言信息装入数据库 PreparedStatement stm = con .prepareStatement("insert into liuyanban_table (title,name,email,content) values('"+ti+"','"+na+"','"+em+"','"+co+"')"); try { stm.executeQuery(); } catch (Exception e) { } // 对留言板中“查看留言”的请求, 服务器端重定向给另一个Servlet来控制 RequestDispatcher requestDispatcher = request .getRequestDispatcher("ViewMessages_servlet"); requestDispatcher.forward(request, response); } catch (Exception e) { e.printStackTrace();
解决方案
数据库对应字段类型对不对?
时间: 2025-01-08 09:01:45