📄 jmdboconntioncall.java
字号:
// data select
// if (!mDbPicConn(oDBSQLBean_.getSQL(), aoDbuse)) {
// pbresult = false;
// }
//
// oDataOut.addItem(SVC_DB_RESULT, pbresult);
// oDataOut.put(SVC_DB_RESULT, new JMVal(pbresult));
// oDataOut.put(SVC_DB_RETURN, new JMVal(oOut));
return oDataOut;
// } catch (Exception e) {
// e.updateSource(CLASS_NAME + "." + sMethod);
// throw e;
} catch (Exception e) {
throw new Exception(CLASS_NAME + "." + sMethod, e);
}
}
protected synchronized JMDBOOutKeyValue mDBasePicSelect () throws Exception {
JMDBOOutKeyValue oDataOut = new JMDBOOutKeyValue();
JM2DArray oOut = new JM2DArray("DBResult");
boolean pbresult = true;
// data select
if (!mDbConnSelect(oDBSQLBean_.getSQL())) {
pbresult = false;
} else {
oOut = JMDBOResultSetApc.getResultData(resultData_);
if (!commit() || !close()) { // || oOut.isEmpty() )
pbresult = false;
}
}
oDataOut.setResult(pbresult);
oDataOut.setResultData(oOut);
return oDataOut;
}
/*
* SQL偺幚峴 ResultSet 僆僽僕僃僋僩偲偟偰尰嵼偺寢壥傪庢摼偟傑偡丅偙偺儊僜僢僪偼丄1 偮偺寢壥偵偮偒 1
* 夞偩偗屇傃弌偝側偗傟偽側傝傑偣傫丅
*/
protected synchronized boolean mDbConnSelect (String sql) throws Exception {
if (JMCheck.isNull(sql))
return false;
if (!mGetDbCon()) {
throw new Exception("DB Connection get err");
}
pstmt_ = conn_.prepareStatement(sql);
resultData_ = pstmt_.executeQuery();
return true;
}
// private String systemDBName = "";
// public void setDbName (String name) {
// systemDBName = name;
// }
protected synchronized boolean mGetDbCon () throws Exception {
final String sMethod = "mGetDbCon";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=" + oDBSQLBean_.getSQLUsedDataBeseName();
conn_ = DriverManager.getConnection(url, "", "");
////////////////Test//////////////////
// oDBConMan_ = ConnectionManager.getInstance();
// conn_ = oDBConMan_.getConnection(oDBSQLBean_.getSQLUsedDataBeseName()); // DriverManager.getConnection
if (conn_ != null) {
conn_.setAutoCommit(false);
} else {
return false;
}
return true;
} catch (Exception e) {
throw new Exception(CLASS_NAME + "." + sMethod, e);
}
}
// /**
// * 蔦uFFFD据库连接处繺uFFFD
// *
// * @param psSql
// * @return
// * @throws Exception
// */
// private synchronized boolean mDbPicConn(String asSql, JM2DArray aoDbuse)
// throws Exception {
// final String sMethod = "mDbPicConn";
//
// try {
// if (!mGetDbCon()) {
// throw new Exception("DB Connection get err");
// }
// statement_ = conn_.prepareStatement(asSql);
// statement_.setString(1, aoDbuse.getStringValue(0, 0));
// statement_.setBytes(2, aoDbuse.getByteArrayValue(1, 0));
// resultData_ = statement_.executeQuery();
// return true;
// } catch (Exception e) {
// e.updateSource(CLASS_NAME + "." + sMethod);
// throw e;
// } catch (Exception e) {
// throw new Exception(CLASS_NAME + "." + sMethod, e);
// }
// }
// ///////////////////////////////////////////////////////////////////
/**
* BaseSqlDao PreparedStatement偵抣愝掕(悢抣)
*/
public void setInt (int intIndex, int intValue) throws SQLException {
this.pstmt_.setInt(intIndex, intValue);
}
/**
* BaseSqlDao PreparedStatement偵抣愝掕(晜摦彮悢)
*/
public void setDouble (int intIndex, double dblValue) throws SQLException {
this.pstmt_.setDouble(intIndex, dblValue);
}
/**
* BaseSqlDao PreparedStatement偵抣愝掕(暥帤)
*/
public void setString (int intIndex, String strValue) throws SQLException {
if (strValue == null) {
this.pstmt_.setNull(intIndex, Types.VARCHAR);
} else {
this.pstmt_.setString(intIndex, strValue);
}
}
/**
* BaseSqlDao PreparedStatement偵抣愝掕(Timestamp)
*/
public void setTimestamp (int intIndex, Timestamp timeValue) throws SQLException {
if (timeValue == null) {
this.pstmt_.setNull(intIndex, Types.TIMESTAMP);
} else {
this.pstmt_.setTimestamp(intIndex, timeValue);
}
}
/**
* BaseSqlDao PreparedStatement偵抣愝掕(Integer)
*/
public void setInteger (int intIndex, Integer intgValue) throws SQLException {
if (intgValue == null) {
this.pstmt_.setNull(intIndex, Types.INTEGER);
} else {
this.pstmt_.setInt(intIndex, intgValue.intValue());
}
}
/**
* BaseSqlDao PreparedStatement偵抣愝掕(Short)
*/
public void setShort (int intIndex, Short shortValue) throws SQLException {
if (shortValue == null) {
this.pstmt_.setNull(intIndex, Types.SMALLINT);
} else {
this.pstmt_.setInt(intIndex, shortValue.shortValue());
}
}
/**
* BaseSqlDao PreparedStatement偵抣愝掕(BigDecimal)
*/
public void setBigDecimal (int intIndex, BigDecimal decValue) throws SQLException {
if (decValue == null) {
this.pstmt_.setNull(intIndex, Types.DECIMAL);
} else {
this.pstmt_.setBigDecimal(intIndex, decValue);
}
}
/**
* BaseSqlDao PreparedStatement偵抣愝掕(Date(java.sql.Date))
*/
public void setDate (int intIndex, java.sql.Date dateValue) throws SQLException {
if (dateValue == null) {
this.pstmt_.setNull(intIndex, Types.DATE);
} else {
this.pstmt_.setDate(intIndex, dateValue);
}
}
// ///////////////////////////////////////////////////////////////////
public synchronized boolean commit () throws Exception {
final String sMethod = "DBCommit";
try {
conn_.commit();
} catch (SQLException e) {
throw new Exception(CLASS_NAME + "." + sMethod, e);
}
return true;
}
public synchronized boolean rollback () throws Exception {
final String sMethod = "DBRollback";
try {
conn_.rollback();
} catch (SQLException e) {
throw new Exception(CLASS_NAME + "." + sMethod, e);
}
return true;
}
public synchronized boolean close () throws Exception {
//final String sMethod = "DBClose";
try {
if (resultData_ != null)
resultData_.close();
} catch (SQLException e) {
}
try {
if (stmt_ != null)
stmt_.close();
} catch (SQLException e) {
}
try {
if (pstmt_ != null)
pstmt_.close();
} catch (SQLException e) {
}
try {
if (conn_ != null)
conn_.close();
} catch (SQLException e) {
}
return true;
}
public boolean release () throws Exception {
final String sMethod = "DBClose";
try {
// ///////////////////////////////////////////////////////////
// 俢俛僐僱僋僔儑儞傪夝曻偡傞
if (!"".equals(oDBSQLBean_.getSQLUsedDataBeseName())) {
oDBConMan_.freeConnection(oDBSQLBean_.getSQLUsedDataBeseName(), conn_);
}
// ///////////////////////////////////////////////////////////
// null
resultData_ = null;
conn_ = null;
stmt_ = null;
pstmt_ = null;
conn_ = null;
} catch (Exception e) {
throw new Exception(CLASS_NAME + "." + sMethod, e);
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -