Topic: 求助(在写入数据库的时候出错!)

  Print this page

1.求助(在写入数据库的时候出错!) Copy to clipboard
Posted by: c00lzhang
Posted on: 2005-11-09 11:41

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>²åÈëÊý¾Ý</title>
</head>
<body>
<%! String ID,Name,Sex,Age,bumen,url,sql;%>
<%! int i;%>
<%! Connection conn;%>
<%! ResultSet rs;%>
<%! Statement stmt;%>
<%
ID=request.getParameter("ID");
Name=request.getParameter("Name");
Name=new String(Name.getBytes("ISO-8859-1"));
Sex=request.getParameter("Sex");
Sex=new String(Sex.getBytes("ISO-8859-1"));
Age=request.getParameter("Age");
bumen=request.getParameter("bumen");
bumen=new String(bumen.getBytes("ISO-8859-1"));
if(ID.length()!=4)
{
response.sendRedirect("err.jsp");
}
if(Name.equals(""))
{
response.sendRedirect("err.jsp");
}
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=gongsi";
conn=DriverManager.getConnection(url,"admin","123456");
stmt=conn.createStatement();
sql="select * from renyuan where ID='"+ID+"'";
rs=stmt.executeQuery(sql);
if(rs.getRow()>0)
  {
response.sendRedirect("err.jsp");
}
sql="insert into renyuan(ID,Name,Sex,Age)";
sql=sql+"values('"+ID+"','"+Name+"','"+Sex+"','"+Age+"','"+i+"')";
stmt.executeUpdate(sql);
out.println("<font size=3 color=blue>ÕýÔÚ´¦ÀíÐÅÏ¢£¬ÇëÉÔºó......</font><meta http-equiv='refresh' content='2;url=list.jsp'>");
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
response.sendRedirect("err.jsp");
}
%>
</body>
</html>
报出的错误是我给的err.jsp但我输入的数据应该没有错

2.Re:求助(在写入数据库的时候出错!) [Re: c00lzhang] Copy to clipboard
Posted by: c00lzhang
Posted on: 2005-11-09 14:14

我觉得是异常的问题 但具体的我不是很清楚

3.Re:求助(在写入数据库的时候出错!) [Re: c00lzhang] Copy to clipboard
Posted by: ntshenwh
Posted on: 2005-11-14 21:51

建议把你这些操作数据的代码封装到一个JAVA BEAN里面,这样看得比较清楚.

4.Re:求助(在写入数据库的时候出错!) [Re: c00lzhang] Copy to clipboard
Posted by: c00lzhang
Posted on: 2005-11-15 08:59

我后面又用servlet来封装过了 但是出了问题啊 ! 我现在不知道问题在哪里?


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923