JAVA连接Oracle
来源:互联网 发布:手机版的淘宝助理 编辑:程序博客网 时间:2024/04/27 19:08
public abstract class BusinessBase extends DAOBase {
/** Log */
protected static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance("SQL");
protected static org.apache.log4j.Category logSQL_Exception = org.apache.log4j.Category.getInstance("SQLException");
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rset = null;
public Connection GetConn() throws Exception
{
try{
conn = getConnection();
}catch(SQLException sqle){
log.error("DBControlMenu:selectKengen::" +
getLogMessage("DB_ERR_CONCLOSE"));
String errmsg = "["+sqle.getErrorCode()+"]"
+ "-" + sqle.getMessage();
throw new Exception(errmsg);
}
return conn;
}
public void CloseConn(Connection conn,PreparedStatement stmt) throws Exception
{
try{
if(stmt != null){
stmt.close();
}
if(conn != null){
release(conn);
}
}catch(SQLException sqle){
log.error("DBControlMenu:selectKengen::" +
getLogMessage("DB_ERR_CONCLOSE"));
String errmsg = "["+sqle.getErrorCode()+"]"
+ "-" + sqle.getMessage();
throw new Exception(errmsg);
}
}
public int ExcuteSQL(ArrayList al)
throws Exception{
String strSQL="";
int RowCount=0;
try{
// DB接続
conn = getConnection();
if(conn == null){
log.error("InServiceUpdateDB:main::conn is null");
throw new Exception(getLogMessage("DB_ERR_GETCON"));
}
conn.setAutoCommit(false);
for(int i=0;i<al.size();i++)
{
strSQL=al.get(i).toString();
log.fatal("認証用SQL=" + strSQL);
stmt = conn.prepareStatement(winToUnicode(strSQL));
RowCount += stmt.executeUpdate();
if(stmt != null){
stmt.close();
}
}
conn.commit();
}catch(SQLException sqle){
sqle.printStackTrace();
try{
conn.rollback();
}
catch(Exception ex)
{
// logSQL_Exception.fatal("SQLException = " +ex);
throw new Exception(ex);
}
throw new Exception(sqle);
}finally{
try{
if(stmt != null){
stmt.close();
}
if(rset != null){
rset.close();
}
if(conn != null){
release(conn);
}
}catch(SQLException sqle){
// logSQL_Exception.fatal("SQLException = " +sqle);
throw new Exception(sqle);
}
}
return RowCount;
}
public int ExcuteSQL(String strSQL)
throws Exception{
try{
// DB接続
conn = getConnection();
if(conn == null){
log.error("InServiceUpdateDB:main::conn is null");
throw new Exception(getLogMessage("DB_ERR_GETCON"));
}
log.fatal("認証用SQL=" + strSQL);
conn.setAutoCommit(false);
stmt = conn.prepareStatement(winToUnicode(strSQL));
int RowCount = stmt.executeUpdate();
conn.commit();
return RowCount;
}catch(SQLException sqle){
// String str = sqle.toString();
// if(str.indexOf("LND_T_HOUZINLOCK")<0)
// {
// logSQL_Exception.fatal("SQLException = " +sqle);
// }
throw new Exception(sqle);
}finally{
try{
if(stmt != null){
stmt.close();
}
if(rset != null){
rset.close();
}
if(conn != null){
release(conn);
}
}catch(SQLException sqle){
// logSQL_Exception.fatal("SQLException = " +sqle);
throw new Exception(sqle);
}
}
}
public ArrayList GetList(String strSQL)
throws Exception{
try{
// DB接続
conn = getConnection();
if(conn == null){
log.error("InServiceUpdateDB:main::conn is null");
throw new Exception(getLogMessage("DB_ERR_GETCON"));
}
log.fatal("認証用SQL=" + strSQL);
stmt = conn.prepareStatement(strSQL);
rset = stmt.executeQuery();
ResultSetMetaData rsmd = rset.getMetaData();
int columnCount = rsmd.getColumnCount();
ArrayList rows = new ArrayList();
while(rset.next()) {
HashMap row = new HashMap();
for (int i = 1; i <= columnCount; i++) {
String name = rsmd.getColumnName(i);
Object obTemp = null;
obTemp = rset.getObject(i);
if (rset.getObject(i) instanceof java.lang.String)
{
try{
obTemp = unicodeToWin(rset.getObject(i).toString());
}
catch(Exception e)
{
//e.printStackTrace();
}
}
row.put(name, obTemp == null ? "" : obTemp);
}
rows.add(row);
}
return rows;
}catch(SQLException sqle){
// String str = sqle.toString();
// if(str.indexOf("LND_T_HOUZINLOCK")<0)
// {
// logSQL_Exception.fatal("SQLException = " +sqle);
// }
throw new Exception(sqle);
}finally{
try{
if(stmt != null){
stmt.close();
}
if(rset != null){
rset.close();
}
if(conn != null){
release(conn);
}
}catch(SQLException sqle){
// logSQL_Exception.fatal("SQLException = " +sqle);
throw new Exception(sqle);
}
}
}
- Java连接Oracle数据库
- JAVA 连接ORACLE数据库
- java连接oracle数据库
- JAVA连接ORACLE
- JAVA 连接 oracle
- java连接oracle数据库
- JAVA连接ORACLE数据库
- java连接Oracle
- JAVA连接Oracle
- java连接oracle数据库
- java连接oracle
- java连接oracle DB
- java连接oracle数据库
- java连接oracle
- java连接oracle数据库
- java 连接 oracle 数据库
- JAVA连接ORACLE
- JAVA连接ORACLE数据库
- 中国的房产市场和房产取向
- 2008-02-02 近日新闻
- 2007年度最佳幽默短篇
- ASP.NET AJAX入门系列(6):UpdateProgress控件简单介绍
- WTL8.0 调用 ActiveX 控件 - (调用 Flash 控件,响应 Flash 控件的事件)
- JAVA连接Oracle
- 自動採番処理
- ASP.NET AJAX入门系列(7):使用客户端脚本对UpdateProgress编程
- .net服务器程序部署的问题汇总
- 使用J2ME发送手机短信息
- ASP.NET AJAX入门系列(8):自定义异常处理
- Registry Trash Keys Finder 3.8
- 执行存储过程通用方法
- 安装Fedora8