日期:2014-05-16  浏览次数:20609 次

超简单的球员MIS(JSP)----ConnDB bean和Player bean
    这是ConnDB bean的源代码:
        -------------------------------------------------------------------------------------
  package com.JSPExperiment.javabean;
  import java.sql.*;
  /**
     * * @author Administrator
  */
  public class ConnDB {
  //the usename of database
   String dbName="root";
   //the password of the database user
   String dbPassword="liao";
   //the URL of the database
   String url="jdbc:mysql://localhost:3306/jspex?useUnicode=true&characterEncoding=GB2312";
   //define a connection object
   Connection dbConn;
   //error statement
   Statement statement;
   ResultSet resultSet;
   /*
            * @initialization operation,including DB connection
     */
  public ConnDB(){
   statement=null;
   resultSet=null;
   //connect DB
   try{
    //声明所用的类包
    Class.forName("com.mysql.jdbc.Driver");
    //获得数据库的连接对象
    dbConn=DriverManager.getConnection(url,dbName,dbPassword);
   }catch(SQLException ex){
    //打印出异常信息
    System.out.println(ex.toString());
   }catch(ClassNotFoundException ex){
    //打印出异常信息
    System.out.println(ex.toString());
   }
  }
  /*
  * @对数据库执行SQL语句,主要是插入和更新操作,返回一个布尔变量值
  */
  public boolean exeSql(String sqlString){
   try{
    statement=dbConn.createStatement();
    statement.executeUpdate(sqlString);
    return true;
   }catch(Exception ex){
    //打印异常信息
    System.out.println(ex.toString());
    return false;
   }
  }
  /*
  * @对数据库执行查询语句,返回一个ResultSet类型的对象
  */
  public ResultSet exeSqlQuery(String sqlString){
   try{
    statement=dbConn.createStatement();
    resultSet=statement.executeQuery(sqlString);
   }catch(Exception ex){
    //打印异常信息
   System.out.println(ex.toString());
   resultSet=null;
   } return resultSet;
  }
}

-----------------------------------------------------------------


以下是Player bean的源代码:
-----------------------------------------------------------------

package com.JSPExperiment.javabean;

import java.util.*;
import java.sql.*;
import java.text.*;

/**
*
* @author Administrator
*/
public class Player extends ConnDB {

    private int PlayerID ;
    private String PlayerName;
    private String PlayerPwd ;
    private String sqlString;
   
    public Player(){
        PlayerID=0;
        PlayerName="";
        PlayerPwd="";
        sqlString="";
    }
   
     /**
     * @return the PlayerID
     */
    p