向数据库中添加数据,不显示错误,可就是显示错误,请各位帮个忙,谢了
<%@page contentType="text/html; charset=GBK" language="java" import="java.sql.*,java.util.*"  %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>添加好友</title>
</head>
<body>
<%!
     String hao,name,hobby,group,city,value,motto,sql;
%>
<jsp:useBean id="myDBconn" class="myBeans.DBconn" scope="page" />
<% 
hao=request.getParameter("hao");
 name=request.getParameter("name").trim();
   hobby=request.getParameter("hobby");
   group=request.getParameter("group");
   city=request.getParameter("city");
value=request.getParameter("value");
motto=request.getParameter("motto");
   if(name.equals(""))
   { 
     out.println("<font size=5 color=blue>对不起,您输入的姓名为空,请重新输入。。</font><meta http-equiv='refresh' content='2;url=insert.jsp'>");
   }
else
{
sql="SELECT* FROM friend where hao='"+hao+"'"; 
 ResultSet RS =myDBconn.executeQuery(sql);
if(RS!=null)
{
if(RS.getRow()>0)
{
  response.sendRedirect("err.jsp");
}
sql="insert into friend(hao,name,hobby,group,city,value,motto)";
sql=sql+"values('"+hao+"','"+name+"','"+hobby+"','"+group+"','"+city+"','"+value+"','"+"','"+motto+"')";
myDBconn.executeUpdate(sql);
out.println("<font size=5 color=blue>正在处理信息,请稍后......</font><meta http-equiv='refresh' content='2;url=friend.jsp'>");
  RS.close();
} }

%>
</body>
</html>

解决方案 »

  1.   

    sql+"values('"+hao+"','"+name+"','"+hobby+"','"+group+"','"+city+"','"+value+"','"+"','"+motto+"')";你插入的值的个数跟你制定的列不对应.    你七个属性 却有七个"," 
      

  2.   

    [Quote=引用 3 楼 dukongting 的回复:]
    同意楼上
    [/Quote。。
      

  3.   

    sql="insert into friend(hao,name,hobby,group,city,value,motto)";// )后少个空格?
    sql=sql+"values('"+hao+"','"+name+"','"+hobby+"','"+group+"','"+city+"','"+value+"','"+"','"+motto+"')";
      

  4.   

    显示正在处理信息 ,应该是执行了SQL语句,可就是没有加到数据库里,急啊 !!!
      

  5.   

    myBeans.DBconn的executeUpdate(sql)帖出来,要是没插入成功,里面应该会出点什么信息
      

  6.   


    sql="insert into friend(hao,name,hobby,group,city,value,motto)";
    sql=sql+"values('"+hao+"','"+name+"','"+hobby+"','"+group+"','"+city+"','"+value+"','"+"','"+motto+"')"改成sql="insert into friend(hao,name,hobby,group,city,value,motto) ";
    sql=sql+"values('"+hao+"','"+name+"','"+hobby+"','"+group+"','"+city+"','"+value+"','"+motto+"')"
      

  7.   

    谢谢,jsp中可以out.print输入的信息,就是加不到数据库里面是不是Java类的原因啊?
      

  8.   


    public int executeUpdate(String sql)
            {
                    int return Val=-999;
                    try
                    {
                            conn=DriverManager.getConnection(ConnStr);
                            Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
                            result=stmt.executeUpdate(sql); 
                    }
                    catch(SQLException ex)
                    {
                            System.err.println("aq.executeUpdate:"+ex.getMessage());//这的错误信息是什么啊,帖出来
                    }
                    return return Val;
            }你这些代码能编译通过?
      

  9.   

    sql+"values('"+hao+"','"+name+"','"+hobby+"','"+group+"','"+city+"','"+value+"','"+"','"+motto+"')";
    应该看看数据库的列是否字符或数字,  是数字就不用加''的
      

  10.   

    给楼主一个快捷的方法。
    如果以后遇到数据库的SQL异常,直接可以
    System.out.println(sql);
    然后再控制台复制你的SQL,粘贴到PL/SQL中执行,然后再看看报错的问题,就找到了。
      

  11.   

    你最好每次把sql语句打印出来
      

  12.   

    sql="insert into friend(hao,name,hobby,group,city,value,motto)";// )后少个空格?
    sql=sql+" values('"+hao+"','"+name+"','"+hobby+"','"+group+"','"+city+"','"+value+"','"+"','"+motto+"')";Value前面加一个空格。