小弟是用的JSP+TOMCAT+MYSQL做的网站
自己照书上写了一个封装数据库操作的类SqlManager,无论在elipse或命令行中调用都可以正确从数据库取回数据并显示,但是一到了JSP页面中使用就自动跳到断点处: bundle = new PropertyResourceBundle(SqlManager.class.getResourceAsStream("/MySQL.properties"));不知道是什么原因,自己实在搞不定了,希望达人帮忙看看,以下是我的SqlManager代码和JSP页面代码:
package bean;
import java.sql.*;
import java.util.PropertyResourceBundle;public class SqlManager {
public String DBhost = null;
public String DBname = null;
public String DBport = null;
public String DBuser = null;
public String DBpassword = null;
    private String jdbcDriver = "";
public String DBurl = null;
    public String DBType = null;

   private static SqlManager p = null;
   private PropertyResourceBundle bundle;
   private String strCon = null;
   
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs   = null;   
         
    
    
//构造SqlManager构造函数
    private SqlManager(){
   try{
   
   
   bundle = new PropertyResourceBundle(SqlManager.class.getResourceAsStream("/MySQL.properties"));
   
   this.DBhost = getString("DBhost");
   this.DBname = getString("DBname");
   this.DBuser = getString("DBuser");
   this.DBname = getString("DBname");
   this.DBport = getString("DBport");
   this.DBurl = getString("DBurl");
   this.DBpassword = getString("DBpassword");
   
   
   
   String database_type = getString("database-type");
   this.DBType = database_type;
 //  if(database_type != null)
  // {
//    System.out.println("1");
//   if(database_type.toLowerCase().equals("mysql"))
 //  {
   jdbcDriver = "com.mysql.jdbc.Driver";
   strCon = DBurl;
//    }
   
//   }
   
   
   
   }catch(Exception e){
   e.printStackTrace();
   }
}
    
   //单态模式
   public static SqlManager createInstance(){
   if(p == null)
   {
   p = new SqlManager();
   p.initDB();
   }
   return p;
   
   }
   
   
   //获取properties中的值
   public String getString(String s){
   return this.bundle.getString(s);
   }

   
   //初始化连接参数
   public void initDB(){
  System.out.println(DBurl);
  System.out.println(jdbcDriver);
  System.out.println(DBType);
  System.out.println(strCon);
  System.out.println(DBuser);
  System.out.println(DBpassword);
   try{
   Class.forName(jdbcDriver);
   }catch(Exception e){
   e.printStackTrace();
   }
   }
   
   
  //连接数据库
   public void connectDB(){
   try{
conn = DriverManager.getConnection(DBurl,DBuser,DBpassword);
stmt = conn.createStatement();
   }catch(SQLException e){
   e.printStackTrace();
   }
   }
   
   public ResultSet executQuery(String sql){
  try{
  rs = stmt.executeQuery(sql);
  }catch(SQLException e){
  e.printStackTrace();
  }
  return rs;
   }
   
   public int executUpdate(String sql){
int ret = 0; 
   try{
  ret = stmt.executeUpdate(sql);
  }catch(SQLException e){
  e.printStackTrace();
  }
  return ret;
   }
   
   public void closeDB()
   {
   try{
   stmt.close();
   conn.close();
 //  rs.close();   这里不能写rs.close 原因目前不清楚
   }catch(SQLException e){
   e.printStackTrace();
   }
   }
/*   public static void main(String args[]){
   SqlManager.createInstance().connectDB();
   SqlManager.createInstance().closeDB();
   }
*/
}
jsp页面
<%@page language="java" import="java.util.*,bean.SqlManager" import="java.sql.*" contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>JDBC连接数据库</title>
</head>
<body>
<% 
String name = request.getParameter("stuName");
String num = request.getParameter("stuId");
String pwd = request.getParameter("password");
 %>
 
 
 <%  String sql = null;
  ResultSet rs  = null;
  int ret;
 
SqlManager DBm = SqlManager.createInstance();
DBm.connectDB();

 
  sql = "insert into login values('" + name +"','" + num + "','" + pwd +"'  )";
  ret = DBm.executUpdate(sql);
  sql = "select * from login";
   rs  = DBm.executQuery(sql);
  while(rs.next())
  {
  String a = rs.getString("username");
  int b =  rs.getInt("number");
  String c = rs.getString("password");
  out.println("姓名:" + a + "<br>");
  out.println("学号:" + b + "<br>");
  out.println("密码:"  + c + "<br>");
  } 
  rs.close();
DBm.closeDB();
 
  %></body>
</html>