|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
关于第二点:俺问问你,如果是企业级项目的话,诸如RMI,EJB,等一些关键技术,这些难道都不需要学么?如果光是使用jsp,servlet,javabean的话。封装|数据|数据库packagecreator.common.db;
importjava.io.InputStream;
importjava.sql.*;
importjavax.sql.*;
importjavax.naming.*;
/**
*
*<p>Title:dbBean.java</p>
*<p>Description:</p>
*<p>Copyright:Copyright(c)2004</p>
*<p>Company:</p>
*@authorTanBo
*@version1.0
*/
publicclassDbBean{
publicjava.sql.Connectionconn=null;//connectionobject
publicResultSetrs=null;//resultsetobject
publicStatementstmt=null;//statementobject
publicPreparedStatementprepstmt=null;//preparedstatementobject
privateStringdrivers=null;//connectionparameter:drivers
privateStringurl=null;//connectionparameter:url
privateStringuser=null;//connectionparameter:user
privateStringpassword=null;//connectionparameter:password
privateStringjndi_name=null;//connectionpoolparameter:jndiname
/**
*init()
*/
publicDbBean(){
try{
//parameterinit
drivers=creator.config.ConfigBundle.getString("drivers");
url=creator.config.ConfigBundle.getString("url");
user=creator.config.ConfigBundle.getString("user");
password=creator.config.ConfigBundle.getString("password");
jndi_name=creator.config.ConfigBundle.getString("jndi_name");
//dbconnectionpoolinit
//InitialContextenv=newInitialContext();
//javax.sql.DataSourcepool=(javax.sql.DataSource)env.lookup(jndi_name);
//conn=pool.getConnection();
//dbconnectioninit
Class.forName(drivers);
conn=DriverManager.getConnection(url,user,password);
//dbstatementinit
stmt=conn.createStatement();
}catch(Exceptione){
System.out.println("dbBean:initerror!"+e.toString());
}
}
/**
*@functionprepareStatement
*@paramsqlString
*@throwsSQLException
*/
publicvoidprepareStatement(Stringsql)throwsSQLException{
prepstmt=conn.prepareStatement(sql);
}
/**
*@functionprepareStatement
*@paramsqlString
*@paramresultSetTypeint
*@paramresultSetConcurrencyint
*@throwsSQLException
*/
publicvoidprepareStatement(Stringsql,intresultSetType,intresultSetConcurrency)
throwsSQLException{
prepstmt=conn.prepareStatement(sql,resultSetType,resultSetConcurrency);
}
/**
*@functionexecuteQuery
*@paramsqlString
*@throwsSQLException
*@returnResultSet
*/
publicResultSetexecuteQuery(Stringsql)throwsSQLException{
if(stmt!=null){
returnstmt.executeQuery(sql);
}elsereturnnull;
}
/**
*@functionexecuteQuery
*@throwsSQLException
*@returnResultSet
*/
publicResultSetexecuteQuery()throwsSQLException{
if(prepstmt!=null){
returnprepstmt.executeQuery();
}elsereturnnull;
}
/**
*@functionexecuteUpdate
*@paramsqlString
*@throwsSQLException
*/
publicvoidexecuteUpdate(Stringsql)throwsSQLException{
if(stmt!=null)
stmt.executeUpdate(sql);
}
/**
*@functionexecuteUpdate
*@throwsSQLException
*/
publicvoidexecuteUpdate()throwsSQLException{
if(prepstmt!=null)
prepstmt.executeUpdate();
}
/**
*@functionexecuteUpdate
*@throwsSQLException
*/
publicvoidexecuteBatch()throwsSQLException{
if(prepstmt!=null)
prepstmt.executeBatch();
}
/**
*@functionaddBatch
*@paramvalueString
*@throwsSQLException
*/
publicvoidaddBatch(Stringvalue)throwsSQLException{
prepstmt.addBatch(value);
}
/**
*@functionsetString
*@paramindexint
*@paramvalueString
*@throwsSQLException
*/
publicvoidsetString(intindex,Stringvalue)throwsSQLException{
prepstmt.setString(index,value);
}
/**
*@functionsetInt
*@paramindexint
*@paramvalueint
*@throwsSQLException
*/
publicvoidsetInt(intindex,intvalue)throwsSQLException{
prepstmt.setInt(index,value);
}
/**
*@functionsetBoolean
*@paramindexint
*@paramvalueboolean
*@throwsSQLException
*/
publicvoidsetBoolean(intindex,booleanvalue)throwsSQLException{
prepstmt.setBoolean(index,value);
}
/**
*@functionsetDate
*@paramindexint
*@paramvalueDate
*@throwsSQLException
*/
publicvoidsetDate(intindex,Datevalue)throwsSQLException{
prepstmt.setDate(index,value);
}
/**
*@functionsetLong
*@paramindexint
*@paramvaluelong
*@throwsSQLException
*/
publicvoidsetLong(intindex,longvalue)throwsSQLException{
prepstmt.setLong(index,value);
}
/**
*@functionsetFloat
*@paramindexint
*@paramvaluefloat
*@throwsSQLException
*/
publicvoidsetFloat(intindex,floatvalue)throwsSQLException{
prepstmt.setFloat(index,value);
}
/**
*@functionsetBytes
*@paramindexint
*@paramvaluebyte[]
*@throwsSQLException
*/
publicvoidsetBytes(intindex,byte[]value)throwsSQLException{
prepstmt.setBytes(index,value);
}
/**
*@functionsetBinaryStream
*@paramindexint
*@paramvalueInputStream
*@paramlenint
*@throwsSQLException
*/
publicvoidsetBinaryStream(intindex,InputStreamvalue,intlen)throwsSQLException{
prepstmt.setBinaryStream(index,value,len);
}
/**
*@functionsetTimestamp
*@paramindexint
*@paramtimestampTimestamp
*@throwsSQLException
*/
publicvoidsetTimestamp(intindex,Timestamptimestamp)throwsSQLException{
prepstmt.setTimestamp(index,timestamp);
}
/**
*@functionsetAutoCommit
*@paramvalueboolean
*@throwsSQLException
*/
publicvoidsetAutoCommit(booleanvalue)throwsSQLException{
if(this.conn!=null)
this.conn.setAutoCommit(value);
}
/**
*@functioncommit
*@throwsSQLException
*/
publicvoidcommit()throwsSQLException{
this.conn.commit();
}
/**
*@functionrollback
*@throwsSQLException
*/
publicvoidrollback()throwsSQLException{
this.conn.rollback();
}
/**
*@functionclose
*@throwsException
*/
publicvoidclose(){
try{
if(rs!=null){
rs.close();
rs=null;
}
}catch(Exceptione){
System.out.println("dbBeancloserserror!");
}finally{
try{
if(stmt!=null){
stmt.close();
stmt=null;
}
}catch(Exceptione){
System.out.println("dbBeanclosestmterror!");
}finally{
try{
if(prepstmt!=null){
prepstmt.close();
prepstmt=null;
}
}catch(Exceptione){
System.out.println("dbBeancloseprepstmterror!");
}finally{
try{
if(conn!=null){
conn.close();
conn=null;
}
}catch(Exceptione){
System.out.println("dbBeancloseconnerror!");
}
}
}
}
}
}
微软什么都提供了。你可以试想一下,如果你是新手,你是希望你点一下按钮程序就能运行那,还是想自己一点一点的组织结构,然后打包发部,调错再打包...... |
|