插入数据库的方法public void up(String name)
{
String sql="insert into userScore(name) values ('"+name+"')";
this.name=name;
try {
st = this.getConn().createStatement() ;
st.executeUpdate(sql) ;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
添加的页面
<body>
   <p align="center">
   <font size="50">添加用户</font>
   <form action="updateUser.jsp" method="post">
   姓名:<input type="text" name="username"><br>
   <input type="submit" value="添加用户">
    <input type="reset" value="取消">   </form>
   updateUser.jsp   
<%  String n=(String)request.getParameter("username");
  System.out.println(n+"   " );
  
  new DBbase().up(n);
  
  response.sendRedirect("show.jsp") ;
  
  
   %>
可是就是添加不到数据库 
测试出来的n是输数字能出来  输文字就出来的是???问号  实在是不懂为什么

解决方案 »

  1.   

    Statement换成PreparedStatement,后面this.getConn().prepareStatement(sql);
      

  2.   

    代码写的好乱。
    目测几个错误,SQL拼错了,汉字问号是中文乱码,你把JSP的ISO-8809-1全换成UTF-8或GBK
      

  3.   

    按照1楼说的,改成
    String sql="insert into userScore(name) values (?);
    this.getConn().prepareStatement(sql);
     ps.setString(1,name)
      

  4.   

    首先你看看你页面的编码格式
    浏览器-》查看-》编码格式,换成GBK或者UTF-8看看。
    String sql="insert into userScore(name) values ('"+name+"')";
    这个应该没有大毛病,但是个空格吧
    String sql="insert into userScore (name) values ('"+name+"')";
    另外更新完了是否需要提交我忘了。
    但是加上提交绝对不会报错。
      

  5.   

    正如楼上所言 你以后写这样的话 最好使用PreparedStatement,注意要养成良好的代码风格,还有最好不要在页面上写代码。
      

  6.   

    这个是乱码了吧  把jsp页面的编码格式和tomcat的编码格式设置成一样,乱码可以解决。