org.YoUmail
Class Mysql

java.lang.Object
  extended byorg.YoUmail.Mysql

public class Mysql
extends java.lang.Object

处理数据库的连接和访问

Version:
1.0 2004-1-15
Author:
topmint

Field Summary
private  javax.sql.DataSource _ds
           
private  java.sql.Connection conn
           
private  java.lang.String dataSourceName
           
private  java.sql.PreparedStatement prepstmt
           
private  java.sql.Statement stmt
           
 
Constructor Summary
Mysql()
          构造数据库的连接和访问类
Mysql(java.lang.String sql)
           
 
Method Summary
 void clearParameters()
          清空参数
 void close()
          关闭连接
 java.sql.ResultSet executeQuery()
          执行预备的SQL语句查询
 java.sql.ResultSet executeQuery(java.lang.String sql)
          执行SQL语句返回字段集
 void executeUpdate()
          执行预备的SQL语句
 void executeUpdate(java.lang.String sql)
          执行SQL语句
 java.sql.Connection getConnection()
          返回连接
 java.sql.PreparedStatement getPreparedStatement()
          返回预设状态
 java.sql.Statement getStatement()
          返回状态
private  void init()
          初始化连接连接池
 void prepareStatement(java.lang.String sql)
           
 void setBoolean(int index, boolean value)
           
 void setDate(int index, java.sql.Date value)
           
 void setFloat(int index, float value)
           
 void setInt(int index, int value)
           
 void setLong(int index, long value)
           
 void setString(int index, java.lang.String value)
          设置对应值
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conn

private java.sql.Connection conn

stmt

private java.sql.Statement stmt

prepstmt

private java.sql.PreparedStatement prepstmt

dataSourceName

private java.lang.String dataSourceName

_ds

private javax.sql.DataSource _ds
Constructor Detail

Mysql

public Mysql()
      throws java.lang.Exception
构造数据库的连接和访问类


Mysql

public Mysql(java.lang.String sql)
      throws java.lang.Exception
Method Detail

init

private void init()
           throws javax.servlet.ServletException,
                  java.sql.SQLException
初始化连接连接池

Throws:
javax.servlet.ServletException
java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
返回连接

Returns:
Connection 连接

prepareStatement

public void prepareStatement(java.lang.String sql)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

setString

public void setString(int index,
                      java.lang.String value)
               throws java.sql.SQLException
设置对应值

Parameters:
index - 参数索引
value - 对应值
Throws:
java.sql.SQLException

setInt

public void setInt(int index,
                   int value)
            throws java.sql.SQLException
Throws:
java.sql.SQLException

setBoolean

public void setBoolean(int index,
                       boolean value)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

setDate

public void setDate(int index,
                    java.sql.Date value)
             throws java.sql.SQLException
Throws:
java.sql.SQLException

setLong

public void setLong(int index,
                    long value)
             throws java.sql.SQLException
Throws:
java.sql.SQLException

setFloat

public void setFloat(int index,
                     float value)
              throws java.sql.SQLException
Throws:
java.sql.SQLException

clearParameters

public void clearParameters()
                     throws java.sql.SQLException
清空参数

Throws:
java.sql.SQLException

getPreparedStatement

public java.sql.PreparedStatement getPreparedStatement()
返回预设状态


getStatement

public java.sql.Statement getStatement()
返回状态

Returns:
Statement 状态

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sql)
                                throws java.sql.SQLException
执行SQL语句返回字段集

Parameters:
sql - SQL语句
Returns:
ResultSet 结果集
Throws:
java.sql.SQLException

executeQuery

public java.sql.ResultSet executeQuery()
                                throws java.sql.SQLException
执行预备的SQL语句查询

Returns:
结果集
Throws:
java.sql.SQLException

executeUpdate

public void executeUpdate(java.lang.String sql)
                   throws java.sql.SQLException
执行SQL语句

Parameters:
sql - SQL语句
Throws:
java.sql.SQLException

executeUpdate

public void executeUpdate()
                   throws java.sql.SQLException
执行预备的SQL语句

Throws:
java.sql.SQLException

close

public void close()
           throws java.lang.Exception
关闭连接

Throws:
java.lang.Exception