<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<%
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e){out.print(e);}
String username=request.getParameter("username");
String password=request.getParameter("password");
username=new String(username.getBytes("ISO-8859-1"),"gb2312");//转字符集,否则查询失败
if(username==null || password==null){username="";password="";};
if(username.equals("") || password.equals("") )out.print("你所留的信息不全");
else
{
Connection newcon;
Statement sql;
ResultSet rs;
String dbpath = application.getRealPath("database/mydata.mdb");//物理路径
String sqlusername="select * from login where username='"+username+"'";
String sqlpass="select username from login where username='"+username+"' and pass='"+password+"'";
//out.print(sqlusername+"<br>");
try
{
String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+dbpath;
newcon=DriverManager.getConnection(url,"","");//无需设置数据源
sql=newcon.createStatement();
rs=sql.executeQuery(sqlusername);
if(!rs.next())//"!rs.next()"是说查询没查到记录,
{
out.println("用户名不存在");
}
else
{
rs=sql.executeQuery(sqlpass);
if(!rs.next())
{
out.println("密码错误");
}
else
{
out.println("登入成功,欢迎你:"+username);
}
}
// while(rs_1.next())
// {
// out.print(rs_1.getString(1)+"----"+rs_1.getString(2)+"<br>");
// }
newcon.close();
}
catch(SQLException e)
{
out.print(e);
}
}
%>
</body>
</html>