package com.skytech.dao;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class DBI {
private static DBI dbi = new DBI();
private static DataSource ds = null;
public static DBI getInstance() {
return dbi;
}
private Connection getConnection() throws SQLException {
String datasource = "java:comp/env/o9i";
Connection conn = null;
try {
if (ds == null) {
InitialContext ctx = new InitialContext();
ds = (DataSource) ctx.lookup(datasource);
}
} catch (NamingException ne) {
throw new SQLException("Lookup Datasource fail." + ne.getMessage());
}
// OracleDataSource ds = new OracleDataSource();
// ds.setURL("jdbc:oracle:thin:trans/trans@localhost:1521:test");
conn = ds.getConnection();
return conn;
}
public ArrayList<ArrayList> query(String sql) {
ArrayList<ArrayList> alRS = new ArrayList<ArrayList>();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
int i = 0;
while (rs.next() != false) {
ArrayList<String> alRow = new ArrayList<String>();
for (i = 1; i <= cols; ++i) {
if (rs.getString(i) == null) {
alRow.add("");
} else {
alRow.add(rs.getString(i));
}
}
alRS.add(alRow);
}
} catch (SQLException sqle) {
sqle.printStackTrace();
throw new RuntimeException("数据库访问异常");
} finally {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException sqle2) {
sqle2.printStackTrace();
throw new RuntimeException("资源关闭异常");
}
}
return alRS;
}
public ArrayList<ArrayList> query(String sql, List alParam) {
ArrayList<ArrayList> alRS = new ArrayList<ArrayList>();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = getConnection();
pstmt = conn.prepareStatement(sql);
setParameters(pstmt, alParam);
rs = pstmt.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
int i = 0;
while (rs.next()) {
ArrayList<String> alRow = new ArrayList<String>();
for (i = 1; i <= cols; ++i) {
if (rs.getString(i) == null) {
alRow.add("");
} else {
alRow.add(rs.getString(i));
}
}
alRS.add(alRow);
}
} catch (SQLException sqle) {
sqle.printStackTrace();
throw new RuntimeException("数据库访问异常");
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException sqle2) {
sqle2.printStackTrace();
throw new RuntimeException("资源关闭异常");
}
}
return alRS;
}
public ArrayList<ArrayList> queryTopN(String sql, int topn) {
ArrayList<ArrayList> alRS = new ArrayList<ArrayList>();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = getConnection();
stmt = conn.createStatement();
String sql_topn = "select rownum as myrownum,a.* from (" + sql
+ ") a where rownum<=" + topn + ")";
rs = stmt.executeQuery(sql_topn);
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
int i = 0;
int j = 0;
while (rs.next()) {
ArrayList<String> alRow = new ArrayList<String>();
for (i = 1; i <= cols; ++i) {
if (rs.getString(i) == null) {
alRow.add("");
} else {
alRow.add(rs.getString(i));
}
}
alRS.add(alRow);
j++;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
throw new RuntimeException("数据库访问异常");
} finally {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException sqle2) {
sqle2.printStackTrace();
throw new RuntimeException("资源关闭异常");
}
}
return alRS;
}
public String queryColumn(String colName, String sql) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String colData = null;
try {
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
colData = rs.next() ? rs.getString(colName) : null;
rs.close();
stmt.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
throw new RuntimeException("数据库访问异常");
} finally {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException sqle2) {
sqle2.printStackTrace();
throw new RuntimeException("资源关闭异常");
}
}
return colData;
}
public double queryMax(String column, String sqlstr) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
double max = 0;
String sql = "select max(" + column + ") maxID from (" + sqlstr + ")";
try {
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
max = rs.next() ? rs.getDouble("maxID") : 0;
rs.close();
stmt.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
throw new RuntimeException("数据库访问异常");
} finally {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException sqle2) {
sqle2.printStackTrace();
throw new RuntimeException("资源关闭异常");
}
}
return max;
}
public int queryCount(String sqlstr, List alParam) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int i_count = 0;
String sql = "select count(*) Count from (" + sqlstr + ")";
try {
conn = getConnection();
pstmt = conn.prepareStatement(sql);
setParameters(pstmt, alParam);
rs = pstmt.executeQuery();
i_count = rs.next() ? rs.getInt("Count") : 0;
rs.close();
pstmt.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
throw new RuntimeException("数据库访问异常");
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException sqle2) {
sqle2.printStackTrace();
throw new RuntimeException("资源关闭异常");
}
}
return i_count;
}
public int queryCount(String sqlstr) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
int i_count = 0;
String sql = "select count(*) Count from (" + sqlstr + ")";
try {
conn = getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
i_count = rs.next() ? rs.getInt("Count") : 0;
rs.close();
stmt.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
throw new RuntimeException("数据库访问异常");
} finally {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException sqle2) {
sqle2.printStackTrace();
throw new RuntimeException("资源关闭异常");
}
}
return i_cou
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
jsp+servlet+dtree+oracle+js+jdbc 员工管理系统 (108个子文件)
DBI.class 15KB
EmpDAO.class 6KB
EmpAction.class 4KB
EmpDTO.class 3KB
SecurityFilter.class 3KB
DeptAction.class 3KB
DeptDAO.class 3KB
Login.class 2KB
MD5.class 2KB
CharactorFilter.class 2KB
LoginBO.class 1KB
DeptDTO.class 1KB
DeptBO.class 1KB
EmpBO.class 270B
.classpath 2KB
styles.css 43KB
calendar-win2k-cold-1.css 5KB
dtree.css 795B
mycss.css 430B
table_bg.gif 5KB
welcome.gif 4KB
sinosoft2.gif 2KB
bar_buttonright.gif 1KB
bar_buttonleft.gif 1KB
globe.gif 1KB
arrowcheck.gif 1KB
trash.gif 1KB
question.gif 1KB
base.gif 1KB
nolines_plus.gif 870B
nolines_minus.gif 861B
musicfolder.gif 633B
imgfolder.gif 622B
page.gif 582B
folderopen.gif 376B
folder.gif 372B
bar_bg.gif 328B
cd.gif 239B
plus.gif 89B
plusbottom.gif 88B
minus.gif 86B
minusbottom.gif 85B
join.gif 69B
joinbottom.gif 66B
line.gif 66B
empty.gif 62B
line_tit.gif 45B
welcome.htm 522B
ojdbc14.jar 1.47MB
standard.jar 385KB
antlr-2.7.2.jar 350KB
struts-core-1.3.8.jar 321KB
struts-el-1.3.8.jar 258KB
struts-taglib-1.3.8.jar 246KB
commons-beanutils-1.7.0.jar 184KB
commons-digester-1.8.jar 140KB
commons-validator-1.3.1.jar 136KB
struts-tiles-1.3.8.jar 117KB
struts-faces-1.3.8.jar 92KB
commons-chain-1.1.jar 88KB
commons-io-1.1.jar 60KB
struts-extras-1.3.8.jar 39KB
commons-logging-1.0.4.jar 37KB
commons-fileupload-1.1.1.jar 31KB
jstl.jar 21KB
struts-mailreader-dao-1.3.8.jar 19KB
struts-scripting-1.3.8.jar 17KB
DBI.java 18KB
EmpDAO.java 4KB
EmpAction.java 3KB
DeptAction.java 3KB
EmpDTO.java 2KB
SecurityFilter.java 2KB
DeptDAO.java 2KB
Login.java 2KB
MD5.java 1KB
CharactorFilter.java 1017B
DeptDTO.java 929B
LoginBO.java 753B
DeptBO.java 654B
EmpBO.java 59B
sinosoft.jpg 51KB
calendar.js 36KB
dtree.js 13KB
calendar-setup.js 4KB
calendar-zh.js 1KB
right.jsp 4KB
preModifyEmp.jsp 4KB
preCreEmp.jsp 4KB
preModDept.jsp 3KB
preCreDept.jsp 2KB
center.jsp 2KB
login.jsp 1KB
left.jsp 1KB
parentFrame.jsp 1KB
top.jsp 721B
index.jsp 48B
MANIFEST.MF 39B
.mymetadata 285B
myEmpDept.pdb 64KB
共 108 条
- 1
- 2
资源评论
- w38122472014-05-27不错,很有参考价值。
- ly9930668862014-04-06看了一下。还不错,有一些还是有参考价值的
- 天才小熊猫121382015-05-12看了一下。还不错,有一些还是有参考价值的
zhouhan0705
- 粉丝: 2
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于opencv的dnn模块实现Yolo-Fastest的目标检测python源码+模型+说明(高分项目).zip
- 使用Python调用微信本地ocr服务.zip
- 【精品推荐】人工智能在医疗中的应用.pptx
- 【精品推荐】电子医疗仪器人机接口-(1).ppt
- 【精品推荐】电子医疗仪器人机接口.ppt
- ubuntu镜像ubuntu镜像01
- 基于paddle搭建神经网络实现5种水果识别分类python源码+数据集(高分毕设).zip
- 【精品推荐】电子商务网店类型介绍.ppt
- 基于paddle搭建神经网络实现水果识别分类python源码+数据集(高分项目).zip
- 三菱plc编程口通信学习笔记.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功