错误出现了很长时间 显示是空指针错误,驱动也验证过了可以连接数据库。
异常报告
datebase.java源代码
#database driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/bookstore-schema username=root password=123456789
package com.hkd.dao;
import java.sql.*;
public class Database {
static String driver;
static String url;
static String username;
static String password;
Connection conn=null;
Statement sm=null;
ResultSet rs=null;
public Connection getConn() {
return conn;
}
public void setConn(Connection conn) {
this.conn = conn;
}
public Database()
{
GetProperty.getFile("database.properties");
driver=GetProperty.getValue("driver");
url=GetProperty.getValue("url");
username=GetProperty.getValue("username");
password=GetProperty.getValue("password");
try {
Class.forName(driver);
conn=DriverManager.getConnection(url,username,password);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ResultSet getResult(String sql)
{
try {
sm=conn.createStatement();
rs=sm.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public void myUpdate(String sql) throws SQLException
{
sm=conn.createStatement();
sm.executeUpdate(sql);
}
public void close()
{
try {
if(rs!=null)
rs.close();
if(sm!=null)
sm.close();
if(conn!=null)
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
jsp源代码
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="com.hkd.service.CategoryServiceImp" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.hkd.entity.Category" %>
register
.a{
border-collapse: collapse;
}
#contrainer{margin:0 auto;width:900Px;}
#header{height:100px;margin-bottom:5px; background-color:#2d6eba}
#center{height:800px; margin-bottom:5px; background-color:#dadbe3}
#footer{height:80px; background-color:#2d6eba}
.red{font-size:10px; color:#F00;}
.green{font-size:10px; color:#0C6}
<%CategoryServiceImp csi=new CategoryServiceImp();
ArrayList clist=csi.checkcategory();
session.setAttribute("catelist", clist);
%>
<%@ include file="header.jsp" %>
<%@ include file="footer.jsp" %>



