- 论坛徽章:
- 0
|
关于Tomcat的MySQL连接池的问题,求救!
- package something;
- import java.sql.*;
- import javax.naming.NamingException;
- public class RsBean
- {
- private ConnMaker connMaker;
- private Connection connection;
- private Statement statement;
- private ResultSet rs;
- private int rows;
- private int cols;
- private String[][] data;
- public int getRows()
- {
- return this.rows;
- }
- public void setRows(int rows)
- {
- this.rows = rows;
- }
- public int getCols()
- {
- return this.cols;
- }
- public void setCols(int cols)
- {
- this.cols = cols;
- }
- public RsBean()
- {
- connMaker = new ConnMaker();
- }
- public double getSum(int col) throws NumberFormatException
- {
- if(data != null)
- {
- double sum = 0D;
- for(int i = 0; i < getRows(); ++i)
- sum += Double.parseDouble(data[col][i]);
- return sum;
- }
- else
- return 0D;
- }
- public void setData(String sql) throws NamingException, SQLException
- {
- try
- {
- connection = connMaker.getConnection();
- statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
- rs = statement.executeQuery(sql);
- rs.last();
- setRows(rs.getRow());
- rs.beforeFirst();
- ResultSetMetaData rsMetaData = rs.getMetaData();
- setCols(rsMetaData.getColumnCount());
- data = new String[cols][rows];
- while(rs.next())
- {
- int row = rs.getRow() - 1;
- for(int col = 0; col < cols; ++col)
- data[col][row] = rs.getString(col + 1);
- }
- }
- finally
- {
- if(rs != null)
- {
- rs.close();
- }
- if(statement != null)
- {
- statement.close();
- }
- if(connection != null)
- {
- connection.close();
- }
- }
- }
- public String[][] getData()
- {
- return data;
- }
- }
复制代码 |
|