求高手指导下,我数据库始终连接不上,麻烦看看

qq_33793203 2016-02-15 10:47:47
登录页面:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" buffer="0kb" autoFlush="true" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>登录页面</title>
<style type="text/css">
<!--
body {
background-image: url(img/bg1.jpg);
}
.STYLE6 {
font-size: 36px;
font-family: "新宋体";
}
-->
</style></head>

<body>
<p class="STYLE6"> </p>
<table width="1240" height="489" border="0" align="center">
<tr>
<td height="87" colspan="3" align="left" class="STYLE6" > 规章班前留题试问补充</td>
</tr>
<tr>
<td align="center"><form id="login" name="login" method="post" action="logDeal.jsp">
<p class="STYLE6"> </p>
<p>
<label>
<input type="radio" name="people" value="user" checked/>
用户</label>
<label>
<input type="radio" name="people" value="admin" />
管理员</label>
</p>
<p>          身份证:
<label>
<input type="text" name="id" id="username" />
</label>
</p>
<p>         密  码:
<label>
<input type="password" name="pwd" id="pwd" />
</label>
</p>
<p>
<label>
            
<input type="submit" name="login" id="login" value="登录" />
</label>  
<input type="reset" name="reset" id="reset" value="重置" />

</p>
</form></td>
</tr>

</table>
</body>
</html>
登录验证界面:
<%@ page contentType="text/html;charset=GBK" import="java.sql.*" %>
<html><title>logDeal</title><body>
<jsp:useBean id="logBeanID" scope="session" class="test.LogBean" />
<%
request.setCharacterEncoding("gbk");
String id=request.getParameter("id");
String pwd=request.getParameter("pwd");
String people=request.getParameter("people");
if((id!=null)&&(pwd!=null)){
id=id.trim();
pwd=pwd.trim();
if(!(id.equals(""))&&!(pwd.equals(""))){
if(people.equals("admin")){
String sql="select ID,password from tb_admin where ID='"+id+"' ";
ResultSet r=logBeanID.executeFetch(sql);

if(r.next()){
String p=logBeanID.judge(r);
if(p.equals(pwd)){
session.setAttribute("admin", id);
out.println(session.getAttribute("admin")+" "+"Welcome !!!");
}
else{
out.println("admin:password error! ");
}
}
else{
out.println(" not admin ");
}

}else if(people.equals("user")){
String sql="select ID,password from tb_user where ID='"+id+"' ";
ResultSet r=logBeanID.executeFetch(sql);
if(r.next()){
String p=logBeanID.judge(r);
if(p.equals(pwd)){
session.setAttribute("user", id);
out.println(session.getAttribute("user")+" "+"Welcome !");
}
else{
out.println("user:passwrd error ! ");
}
}
else{
out.println(" not user");
}
}
}else
out.println("Place rightly input !! ");
}else
out.println(" not null !!!");
%>
</body>
</html>

JavaBean代码:
package test;
import java.sql.*;
public class LogBean{

String driver="sun.jdbc.odbc.JdbcOdbcDriver";
Statement stmt=null;
String sql=null;
ResultSet r=null;
Connection con =null;
String p="";
String bn="";
public LogBean(){
try{ System.out.println("0");

Class.forName(driver);
}catch(Exception e){

System.out.println("连接数据库出错aaaaaa");
e.printStackTrace();
}
System.out.println("1");


try{ String url = "jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=E:/tielu.mdb";
System.out.println("2");

Connection con =DriverManager.getConnection(url,"","");
System.out.println("3");
stmt=con.createStatement();
System.out.println("4");
}catch(Exception e){

System.out.println("aaaaaa");
e.printStackTrace();
}
}
public ResultSet executeFetch(String sql){

try{
r=stmt.executeQuery(sql);
}catch(SQLException e){
System.out.println(" error : fetch !");
e.printStackTrace();
}
catch(NullPointerException e){
System.out.println(" error : null fetch !");
e.printStackTrace();
}
return r;
}

public String judge(ResultSet r){
try{
if(r.next()){
p=r.getString("password");
}
}catch(SQLException e){
System.out.println(" error : fetch !");
e.printStackTrace();
}
catch(NullPointerException e){
System.out.println(" error : null fetch !");
e.printStackTrace();
}
return p;

}
public void destroy(){
if(stmt!=null){
try{
stmt.close();
con.close();
}catch(SQLException e){
System.out.println(" error : destroy !");
e.printStackTrace();
}
}
}

}
运行后出现的错误:org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:532)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:426)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.NullPointerException
org.apache.jsp.logDeal_jsp._jspService(logDeal_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
...全文
128 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
qq_33793203 2016-02-16
我没懂你的意思,求详细说下,谢谢
回复
兔子托尼啊 2016-02-16
到编译后的logDeal_jsp.java:79 看看 79 行这个
回复
yes?? 2016-02-16
你这个项目里有一个类,logDeal_jsp.java,去看这个类的第七十九行。空指针异常。 一般是遇到null了,你要写个判断,如果是null抛个异常出去。
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2016-02-15 10:47
社区公告
暂无公告