jsp的问题(0分)

  • 主题发起人 xiaotianwangzi
  • 开始时间
X

xiaotianwangzi

Unregistered / Unconfirmed
GUEST, unregistred user!
下面代码老是提示出错。不能运行.说是一个sql语句错误.哪位老师帮帮忙
出错的代码是:
sql="select * from user where user='"+temp1+"' and password='"+temp2+"'";
源文件:
<%@ page import="java.sql.*"%>
<html>
<head>
<title>用户管理</title>
<meta http-equiv="content-type" content="text/html;charset="gb2312">
</head>
<body bgcolor="#9999ff">
<div align="center">
<p>&amp;nbsp;</p>
<p><font size="5"><b><font color="#000000">用户窗口</font></b>
</font></p>
<p>&amp;nbsp;</p>
<%
int n;
String temp1=new String();
String temp2=new String();
temp1=request.getParameter("txtname");
temp2=request.getParameter("txtpassword");
n=temp1.length()*temp2.length();
if(n==0) {
%>
<p>您的输入有误,请重新输入。</p>
<p><a href="user.jsp">返回</a>
</p>
<%
}
else
{
String tempuser=new String();
String tempid=new String();
int tempupnum;
String url=new String();
url="jdbc:eek:dbc:usergl";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
String sql=new String();
sql="select * from user where user='"+temp1+"' and password='"+temp2+"'";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
tempuser=rs.getString("user");
tempid=rs.getString("id");
tempupnum=rs.getInt("upnum")+1;
rs.close();
sql="UPDATE user SET upnum="+Integer.toString(tempupnum)+"where user='"+temp1+"'";
%>
<%
int i=stmt.executeUpdate(sql);
session.putValue("user",tempuser);
%>
<p><b>用户<%=tempuser%>(<%=tempid%>),您好!</b></p>
<p><b>您已经上站<%=tempupnum%>次。</b></p>
<p>本窗口为您提供记事本</p>
<p><a href="notebook3.jsp">查看记事本中的信息</a></p>
<p><a href="notebook1.jsp">向记事本中添加信息</a>
</p>
<%}
else
{
%>
<p>这个用户不存在,请重新登陆。</p>
<p>如果你还没有注册,请立即注册</p>
<p><a href="user.jsp">返回</a></p>
<p><a href="zhuce1.jsp">注册</a></p>
<%
}
stmt.close();
con.close();
}
%>
</div>
</body>
</html>
 
既然出错,又不肯告诉我们是什么错误,这叫我们如何是好?
 
多谢了。我再详细的说一遍.
在运行时就是我给出的第一行sql语句,提示前面是一段乱码
后面是 '1where user='temp1''不知道为什么在where的前面出现了一个1
 
提示语法错误(操作符丢失)
在查询表达式 '1where user='yonghuuming''中
 
我看错的是
sql="UPDATE user SET upnum="+Integer.toString(tempupnum)+"where user='"+temp1+"'";
而不是
sql="select * from user where user='"+temp1+"' and password='"+temp2+"'";
试下改为
sql="UPDATE user SET upnum='"+Integer.toString(tempupnum)+"' where user='"+temp1+"'";
或改为:
sql="UPDATE user SET upnum='"+tempupnum+"' where user='"+temp1+"'";
 
接受答案了.
 
顶部