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>&nbsp;</p>
<p><font size="5"><b><font color="#000000">用户窗口</font></b>
</font></p>
<p>&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="jdbcdbc: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="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>&nbsp;</p>
<p><font size="5"><b><font color="#000000">用户窗口</font></b>
</font></p>
<p>&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="jdbcdbc: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>