我写的数据库操作类DBUtil


package org.evilbinary.db;
import java.sql.*;
import java.util.Vector;

public class DBUtil {
    private String userName;
    private String password;
    private String connectUrl;
    private String driverName;
    private Statement statement;
    private PreparedStatement preparedStatement;
    private Connection connection;
    private ResultSet resultSet;
    private CallableStatement callStatement;
    public DBUtil(){
        driverName="com.mysql.jdbc.Driver";
        connectUrl="jdbc:mysql://localhost:3306/oj";
        userName="root";
        password="123";
        connect();
    }
    public DBUtil(String connectUrl,String userName,String password){
        driverName="com.mysql.jdbc.Driver";
        this.connectUrl=connectUrl;
        this.userName=userName;
        this.password=password;
        connect();
    }
    public void connect(){
        if(connection!=null)
            return;
        try {
            Class.forName(driverName);
            connection=DriverManager.getConnection(connectUrl,userName,password);
        } catch (ClassNotFoundException e) {
            System.out.println("jdbc driver can not found!"+e.getMessage());
        } catch (SQLException e) {
            System.out.println("connect failed!"+e.getMessage());
        }catch(Exception e){
            System.out.println("Error!"+e.getMessage());
        }
    }
    public void close(){
        try {
            if(statement!=null&&!statement.isClosed())
                statement.close();
            if(callStatement!=null&&!callStatement.isClosed())
                callStatement.close();
            if(preparedStatement!=null&&!preparedStatement.isClosed())
                preparedStatement.close();
            if(connection!=null&&!connection.isClosed())
                connection.close();
            
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public void executeQuery(String sql){
        try {
            statement=connection.createStatement();
            resultSet=statement.executeQuery(sql);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            System.out.println("executeQuery failed!"+e.getMessage());
        }catch(Exception e){
            System.out.println("executeQuery error!"+e.getMessage());
        }
    }
    public void executeQuery(String sql,String parameters[]){
        try {
            preparedStatement=connection.prepareStatement(sql);
            for(int i=0;i getResultsVectorStrings(){
        
        ResultSetMetaData resultSetMetaData;
        Vector vv=new Vector();
        try {
            resultSetMetaData = resultSet.getMetaData();
            int numCols=resultSetMetaData.getColumnCount();
            while(resultSet.next())
            { 
                String[] v=new String[numCols];
                for(int i=0;i
public class Main {
    /**
     * @param args
     */
    public static void output(Vector vv){
        for(int i=0;i vv=db.getResultsVectorStrings();
////		output(vv);
////		db.executeQuery("select a from s");
////		vv=db.getResultsVectorStrings();
////		output(vv);
////		Vector v=db.getResultsVectorColum(2);
////		for(int i=0;i