📄 abstractdbexecutor.java
字号:
package org.speedframework.db.executor;
import org.speedframework.convert.QueryInDataConverUtil;
import org.speedframework.exception.SpeedFrameworkException;
import java.sql.*;
/**
* Class AbstractDBExecutor
*
* @author <a href="mailto:santafeng@gmail.com"> lizf </a>
* @version $Revision:1.0.0, $Date: 2007-11-22 上午01:34:19 $
*/
public abstract class AbstractDBExecutor implements DBExecutor {
protected Connection con;
public void setCon(Connection con) {
this.con = con;
}
public ResultSet setExecuteQuery(PreparedStatement ps, Object[] parmvalue)
throws SQLException {
if (parmvalue.length > 0) {
for (int i = 0; i < parmvalue.length; i++) {
QueryInDataConverUtil
.importData(ps, i + 1, parmvalue[i], false);
}
}
return ps.executeQuery();
}
public int[] executeBatch(String SQL, Object[][] params)
throws SpeedFrameworkException, SQLException {
if (SQL == null) {
throw new SpeedFrameworkException(" SQL is null ");
}
if (con == null) {
throw new SpeedFrameworkException(" Connection is null ");
}
PreparedStatement ps = null;
int[] reValue = null;
try {
ps = con.prepareStatement(SQL);
for (int i = 0; i < params.length; i++) {
for (int j = 0; j < params[i].length; j++) {
ConvertUtil.importData(ps, j + 1, params[i][j], false);
}
ps.addBatch();
}
reValue = ps.executeBatch();
} catch (Exception ex) {
throw new SpeedFrameworkException(ex.getMessage());
} finally {
if (ps != null) {
ps.close();
}
}
return reValue;
}
public boolean setExecuteCall(CallableStatement proc, String SQL,
Object[] parmvalue) throws SQLException, SpeedFrameworkException {
if (SQL == null) {
throw new SpeedFrameworkException(" SQL is null ");
}
if (con == null) {
throw new SpeedFrameworkException(" Connection is null ");
}
proc = con.prepareCall(SQL);
for (int i = 0; i < parmvalue.length; i++) {
ConvertUtil.importData(proc, i + 1, parmvalue[i], false);
}
return proc.execute();
}
public Object setFunctionCall(CallableStatement proc, String SQL,
Object[] parmvalue, int returnType) throws SQLException,
SpeedFrameworkException {
if (SQL == null) {
throw new SpeedFrameworkException(" SQL is null ");
}
if (con == null) {
throw new SpeedFrameworkException(" Connection is null ");
}
proc = con.prepareCall(SQL);
proc.registerOutParameter(1, returnType);
for (int i = 0; i < parmvalue.length; i++) {
ConvertUtil.importData(proc, i + 2, parmvalue[i], false);
}
proc.execute();
return proc.getObject(1);
}
public int executeSpecial(String SQL, Object[] parmvalue)
throws SQLException, SpeedFrameworkException {
if (SQL == null) {
throw new SpeedFrameworkException(" SQL is null ");
}
if (con == null) {
throw new SpeedFrameworkException(" Connection is null ");
}
PreparedStatement ps = null;
int reValue = 0;
try {
ps = this.con.prepareStatement(SQL);
for (int i = 0; i < parmvalue.length; i++) {
ConvertUtil.importData(ps, i + 1, parmvalue[i], false);
}
reValue = ps.executeUpdate();
} catch (Exception ex) {
throw new SpeedFrameworkException(ex.getMessage());
} finally {
if (ps != null) {
ps.close();
}
}
return reValue;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -