DWR.docx

上传人:b****7 文档编号:9380294 上传时间:2023-02-04 格式:DOCX 页数:19 大小:17.47KB
下载 相关 举报
DWR.docx_第1页
第1页 / 共19页
DWR.docx_第2页
第2页 / 共19页
DWR.docx_第3页
第3页 / 共19页
DWR.docx_第4页
第4页 / 共19页
DWR.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

DWR.docx

《DWR.docx》由会员分享,可在线阅读,更多相关《DWR.docx(19页珍藏版)》请在冰豆网上搜索。

DWR.docx

DWR

DWR整理:

导入:

dwr.jar包

//下拉菜单选项

Jsp:

varstatus='

outvalue="${pageMap.pageInfo.status}"/>';//理赔状态

varclmRsn='

outvalue="${pageMap.pageInfo.clmRsn}"/>';

functioninitPage(){

showSelect('250','status',status);showSelect('310','clmRsn',clmRsn);

}

functionshowSelect(dictType,id,defaultValue){

commDictDWR.qryCommDictByType(dictType,function(date){

DWRUtil.addOptions(id,{"":

"请选择"});

DWRUtil.addOptions(id,date,"id","name");

DWRUtil.setValue(id,defaultValue);

});

}

Java:

publicclassCommDictDWR{

/**

*通过字典类型代码取得字段清单

*

*@paramtype

*字典类型代码

*@return

*@throwsException

*/

publicList>qryCommDictByType(Stringtype)throwsException{

List>list=newArrayList>();

Mapmap=null;

DBPooldb=null;

try{

Stringsql="selectC_DICT_CDE,C_DICT_NMEfromTB_COMM_DICTwhereC_DICT_TYPE=?

andC_STATE='1'orderbyC_DICT_CDE";

db=newDBPool(DBConnection.getDBConnection());

db.prepareStatement(sql);

db.setString(1,type);

ResultSetrs=db.executeQuery();

while(rs.next()){

map=newHashMap();

map.put("id",rs.getString("C_DICT_CDE"));

map.put("name",rs.getString("C_DICT_NME"));

list.add(map);

}

rs.close();

rs=null;

}catch(Exceptione){

e.printStackTrace();

thrownewException("根据字典类型代码查询字典清单出错");

}finally{

db.close();

}

returnlist;

}

}

Dwr.xml配置:

xmlversion="1.0"encoding="UTF-8"?

>

DOCTYPEdwrPUBLIC"-//GetAheadLimited//DTDDirectWebRemoting2.0//EN""http:

//www.getahead.ltd.uk/dwr/dwr20.dtd">

value="mon.CommDictDWR"/>

......

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 文学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1