向数据库中添加数据,不显示错误,可就是显示错误,请各位帮个忙,谢了
<%@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>
<%@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>
同意楼上
[/Quote。。
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+"')"改成sql="insert into friend(hao,name,hobby,group,city,value,motto) ";
sql=sql+"values('"+hao+"','"+name+"','"+hobby+"','"+group+"','"+city+"','"+value+"','"+motto+"')"
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;
}你这些代码能编译通过?
应该看看数据库的列是否字符或数字, 是数字就不用加''的
如果以后遇到数据库的SQL异常,直接可以
System.out.println(sql);
然后再控制台复制你的SQL,粘贴到PL/SQL中执行,然后再看看报错的问题,就找到了。
sql=sql+" values('"+hao+"','"+name+"','"+hobby+"','"+group+"','"+city+"','"+value+"','"+"','"+motto+"')";Value前面加一个空格。