match="mset.dto.CommDict">
Web.xml配置:
dwr-invoker
/dwr/*
DBPool的封装类:
importjava.io.InputStream;
importjava.math.BigDecimal;
importjava.sql.Connection;
importjava.sql.Date;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjava.sql.Timestamp;
importjavax.naming.InitialContext;
importjavax.naming.NamingException;
importjavax.sql.DataSource;
importjavax.sql.RowSet;
importcom.sun.rowset.CachedRowSetImpl;
publicclassDBPool{
privatestaticDataSourcedatasource2=null;
privatejava.sql.Connectionconn=null;
privateResultSetrs=null;
privateStatementstmt=null;
privatePreparedStatementprepstmt=null;
publicDBPool(){
}
/**
*得到数据源连接
*
*@return
*@throwsException
*@throwsSQLException
*/
privatestaticConnectionsetConnection()throwsException{
Connectionconnection=null;
try{
if(datasource2==null){
InitialContextinitialcontext=newInitialContext();
//GetDSfromJNDI
datasource2=(DataSource)initialcontext.lookup("java:
/hacdxDS");
}
connection=datasource2.getConnection();
}catch(NamingExceptionnamingexception){
namingexception.printStackTrace();
thrownamingexception;
}catch(SQLExceptionsqlexception){
sqlexception.printStackTrace();
throwsqlexception;
}catch(Exceptione){
e.printStackTrace();
throwe;
}
returnconnection;
}
publicDBPool(Connectionconnection)throwsSQLException{
try{
this.conn=connection;
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
//只读的形式取数据
}catch(SQLExceptione){
throwe;
}
}
publicDBPool(booleanisConnection)throwsException{
try{
if(isConnection){
this.conn=setConnection();
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
//只读的形式取数据
}
}catch(SQLExceptione){
throwe;
}
}
publicvoidsetConnection(Connectionconnection)throwsSQLException{
try{
this.conn=connection;
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}catch(SQLExceptione){
throwe;
}
}
/**
*@functionprepareStatement
*@paramsql
*String
*@throwsSQLException
*/
publicvoidprepareStatement(Stringsql)throwsSQLException{
if(prepstmt!
=null){
prepstmt.close();
prepstmt=null;
}
if(null==conn){
System.out.println("连接为空!
!
!
!
!
!
!
!
");
}
prepstmt=conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}
/**
*@functionprepareStatement
*@paramsbSql
*StringBuffer
*@throwsSQLException
*/
publicvoidprepareStatement(StringBuffersbSql)throwsSQLException{
if(prepstmt!
=null){
prepstmt.close();
prepstmt=null;
}
if(null==conn){
System.out.println("连接为空!
!
!
!
!
!
!
!
");
}
prepstmt=conn.prepareStatement(sbSql.toString(),ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}
/**
*functiongetaconnection
*
*@returnConnection
*/
publicConnectiongetConnection()throwsSQLException{
returnconn;
}
/**
*@functionprepareStatement
*@paramsql
*String
*@paramresultSetType
*int
*@paramresultSetConcurrency
*int
*@throwsSQLException
*/
publicvoidprepareStatement(Stringsql,intresultSetType,intresultSetConcurrency)throwsSQLException{
prepstmt=conn.prepareStatement(sql,resultSetType,resultSetConcurrency);
}
/**
*@functionexecuteQuery
*@paramsql
*String
*@throwsSQLException
*@returnResultSet
*/
publicResultSetexecuteQuery(Stringsql)throwsSQLException{
if(stmt!
=null){
returnstmt.executeQuery(sql);
}else{
returnnull;
}
}
/**
*@functionexecuteQuery
*@throwsSQLException
*@returnResultSet
*/
publicRowSetexecuteQuery()throwsSQLException{
CachedRowSetImplrowset=newCachedRowSetImpl();
ResultSetrs=null;
if(prepstmt!
=null){
rs=prepstmt.executeQuery();
rowset.populate(newResultSetWrapper(rs));
rs.close();
prepstmt.close();
rs=null;
prepstmt=null;
}else{
returnnull;
}
returnrowset;
}
publicvoidexecuteSql(Stringsql)throwsSQLException{
if(stmt!
=null){
stmt.execute(sql.trim());
}else{
thrownewSQLException("数据库连接失败");
}
}
/**
*@functionexecuteUpdate
*@paramsql
*String
*@throwsSQLException
*/
publicvoidexecuteUpdate(Stringsql)throwsSQLException{
if(stmt!
=null){
stmt.executeUpdate(sql);
}
}
/**
*@functionexecuteUpdate
*@throwsSQLException
*/
publicintexecuteUpdate()throwsSQLException{
inti=-1;
if(prepstmt!
=null){
i=prepstmt.executeUpdate();
prepstmt.close();
prepstmt=null;
}
returni;
}
publicvoidexecute()throwsSQLException{
if(prepstmt!
=null){
prepstmt.execute();
prepstmt.close();
prepstmt=null;
}
}
/**
*@functionexecuteUpdate
*@throwsSQLException
*/
publicvoidexecuteBatch()throwsSQLException{
if(prepstmt!
=null){
prepstmt.executeBatch();
}
}
/**
*@functionaddBatch
*@paramvalue
*String
*@throwsSQLException
*/
publicvoidaddBatch(Stringvalue)throwsSQLException{
prepstmt.addBatch(value);
}
publicvoidaddBatch()throwsSQLException{
prepstmt.addBatch();
}
publicvoidclearBatch()throwsSQLException{
prepstmt.clearBatch();
}
publicvoidprepstmtClose()throwsSQLException{
prepstmt.close();
}
publicvoidsetString(intindex,Stringvalue)throwsSQLException{
prepstmt.setString(index,value);
}
publicvoidsetObject(intindex,Objectvalue)throwsSQLException{
prepstmt.setObject(index,value);
}
publicvoidsetInt(intindex,intvalue)throwsSQLException{
prepstmt.setInt(index,value);
}
publicvoidsetBigDecimal(intindex,BigDecimalvalue)throwsSQLException{
prepstmt.setBigDecimal(index,value);
}
publicvoidsetBoolean(intindex,booleanvalue)throwsSQLException{
prepstmt.setBoolean(index,value);
}
/**
*@functionsetDate
*@paramindex
*int
*@paramvalue
*Date
*@throwsSQLException
*/
publicvoidsetDate(intindex,Datevalue)throwsSQLException{
prepstmt.setDate(index,value);
}
/**
*@functionsetLong
*@paramindex
*int
*@paramvalue
*long
*@throwsSQLException
*/
publicvoidsetLong(intindex,longvalue)throwsSQLException{
prepstmt.setLong(index,value);
}
/**
*@functionsetFloat
*@paramindex
*int
*@paramvalue
*float
*@throwsSQLException
*/
publicvoidsetFloat(intindex,floatvalue)throwsSQLException{
prepstmt.setFloat(index,value);
}
/**
*@functionsetBytes
*@paramindex
*int
*@paramvalue
*byte[]
*@throwsSQLException
*/
publicvoidsetBytes(intindex,byte[]value)throwsSQLException{
prepstmt.setBytes(index,value);
}
/**
*@functionsetBinaryStream
*@paramindex
*int
*@paramvalue
*InputStream
*@paramlen
*int
*@throwsSQLException
*/
publicvoidsetBinaryStream(intindex,InputStreamvalue,intlen)throwsS