package database;
import java.sql.*;
//import oracle.jdbc.driver.*;
import javax.naming.NamingException;
public class DBConnectionManager
{
protected transient Connection dbConnection = null;
protected transient CallableStatement callStat = null;
protected transient Statement stmt = null;
protected transient ResultSet resultSet = null;
private transient PreparedStatement PrepStmt = null;
public DBConnectionManager() {
}
DBConnection db=new DBConnection();
public void Open(String path) throws SQLException, ClassNotFoundException {
// dbConnection=db.getConnFromProperties();
dbConnection=db.getConn(path);
stmt=dbConnection.createStatement();
}
public Statement CreateStatement(Connection dbConnection) throws SQLException {
Statement stmt = dbConnection.createStatement();
return stmt;
}
public DatabaseMetaData getMetaData() throws SQLException {
DatabaseMetaData dbMeta = dbConnection.getMetaData();
return dbMeta;
}
public PreparedStatement getPrepStmt(String StrSql) throws SQLException {
PrepStmt = dbConnection.prepareStatement(StrSql);
return PrepStmt;
}
public void AddBatch(String StrSql) throws SQLException {
stmt.addBatch(StrSql);
}
public int[] ExecBatch() throws SQLException {
return (stmt.executeBatch());
}
public void SetMaxTime(Statement stmt, int times) throws SQLException {
stmt.setQueryTimeout(times);
}
public Connection getConnection() throws SQLException {
return this.dbConnection;
}
public void ExecuteSQL(String sqlSentence) throws SQLException {
resultSet = stmt.executeQuery(sqlSentence);
}
public ResultSet QueryRs(String sqlSentence) throws SQLException {
resultSet = stmt.executeQuery(sqlSentence);
return resultSet;
}
public int UpdateSQL(String sqlSentence) throws SQLException,NamingException {
int i=-1;
i=stmt.executeUpdate(sqlSentence);
return i;
}
public void ExecuteCall(String callName, String[] Volume) throws SQLException {
// String re = "";
int i;
i = 0;
try {
callStat = dbConnection.prepareCall("{ call " + callName + " }");
for (i = 0; i < Volume.length; i++) {
callStat.setString(i + 1, Volume[i]);
}
callStat.execute();
}
catch (SQLException ex) {
System.err.println("getSequence :" + ex);
}
}
// public void DoAffair(SessionContext sessionContext, Collection coll) throws
// SQLException {
// UserTransaction ut = sessionContext.getUserTransaction();
// try {
// ut.begin();//事务开始
// this.Open();//打开数据库连接
// Iterator oi = (java.util.Iterator) coll.iterator();
// while (oi.hasNext()) {
// String sql = (String) oi.next();
// this.UpdateSQL(sql);
// }
// this.Close();//关闭数据库连接
// ut.commit();//提交事务
// }
// catch (Exception ex) {
// try {
// ut.rollback();//回滚
// this.Close();//关闭数据库连接
// throw ex;
// }
// catch (Exception e) {
// this.Close();//关闭数据库连接
// }
// }
// }
// public void dump() {
// ic = null;
// dataSource = null;
// }
public void Close() {
CloseStmt();
CloseRs();
CloseCon();
CloseCallStm();
ClosePrepStmt();
// dump();
}
public void CloseRs() {
try {
if (resultSet != null) {
resultSet.close();
}
}
catch (Exception ex) {}
}
/**
* 关闭数据库连接
*/
public void CloseCon() {
try {
if (dbConnection != null) {
dbConnection.close();
}
}
catch (Exception ex) {}
}
/**
* 关闭Statement
*/
public void CloseStmt() {
try {
if (stmt != null) {
stmt.close();
}
}
catch (Exception ex) {}
}
/**
* 关闭预处理语句
*/
public void ClosePrepStmt() {
try {
if (PrepStmt != null) {
PrepStmt.close();
}
}
catch (Exception ex) {}
}
/**
* 关闭CallAbleStatement
*/
public void CloseCallStm() {
try {
if (callStat != null) {
callStat.close();
}
}
catch (Exception ex) {}
}
public void setAutoCommit(boolean isAutoCommit){
try {
dbConnection.setAutoCommit(isAutoCommit);
} catch (SQLException e) {
e.printStackTrace();
}
}
public void commit(){
try {
dbConnection.commit();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void rollback(){
try {
dbConnection.rollback();
} catch (SQLException e) {
e.printStackTrace();
}
}
//public static void main(String[] args) {
// BaseDAO basedao=new BaseDAO();
// try {
// basedao.Open();
// } catch (SQLException e) {
// // TODO 自动生成 catch 块
// e.printStackTrace();
// }
//
//}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
webtree.rar (66个子文件)
codefans.net
webtree
.project 1KB
.mymetadata 285B
WebRoot
css
dtree.css 914B
tree.css 3KB
WEB-INF
web.xml 286B
lib
classes
tree
TreeDAO.class 2KB
TreeBean.class 2KB
welltree
WellTreeDAO.class 3KB
WellTreeBean.class 2KB
Utils.class 2KB
database
DBConnection.class 4KB
jdbc.properties 335B
DBConnectionManager.class 5KB
welltree.jsp 3KB
META-INF
MANIFEST.MF 39B
db
tree.mdb 39.88MB
welltree1.jsp 3KB
dTree.jsp 2KB
script
MzTreeView10.js 23KB
dtree.js 13KB
dtreeimages
plusbottom.gif 231B
plus.gif 230B
empty.gif 62B
line.gif 114B
joinbottom.gif 850B
folderopen.gif 375B
minus.gif 244B
minusbottom.gif 240B
base.gif 1KB
join.gif 857B
Thumbs.db 11KB
page.gif 582B
folder.gif 397B
images
collection.gif 369B
P2.gif 163B
exit.gif 170B
M0.gif 159B
bgSubHeading.gif 169B
property.gif 132B
L2.gif 68B
P1.gif 166B
P0.gif 163B
folderopen.gif 376B
M1.gif 163B
L3.gif 63B
P3.gif 159B
L4.gif 69B
M3.gif 156B
L0.gif 66B
M2.gif 159B
L1.gif 73B
L5.gif 58B
Thumbs.db 26KB
root.gif 1KB
file.gif 572B
folder.gif 372B
tree.jsp 2KB
.myeclipse
src
tree
TreeBean.java 2KB
TreeDAO.java 2KB
welltree
Utils.java 850B
WellTreeBean.java 1KB
WellTreeDAO.java 3KB
database
DBConnectionManager.java 5KB
jdbc.properties 335B
DBConnection.java 3KB
.classpath 340B
共 66 条
- 1
资源评论
boriskong
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功