dbconnection.java
来自「Struts入门的一个好例子 Struts入门的一个好例子」· Java 代码 · 共 99 行
JAVA
99 行
package bily.notebook.struts.iBatis;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.event.RowHandler;
public class DBConnection {
private SqlMapClient client;
public DBConnection() throws DatabaseException {
SqlMapClient client = DBAccessFactory.getSqlMap();
this.client = client;
}
public void openTransaction() throws SQLException {
client.startTransaction();
}
public void commitTransaction() throws SQLException {
client.commitTransaction();
}
public void closeTransaction() throws SQLException {
client.endTransaction();
}
public int update(String statementName, Object parameterObject)
throws SQLException {
return client.update(statementName, parameterObject);
}
public Object insert(String statementName, Object parameterObject)
throws SQLException {
return client.insert(statementName, parameterObject);
}
public int delete(String statementName, Object parameterObject)
throws SQLException {
return client.delete(statementName, parameterObject);
}
public Object executeQueryForObject(String statementName,
Object parameterObject) throws SQLException {
return client.queryForObject(statementName, parameterObject);
}
public Object executeQueryForObject(String statementName,
Object parameterObject, Object resultObject) throws SQLException {
return client.queryForObject(statementName, parameterObject,
resultObject);
}
public Map<?, ?> executeQueryForMap(String statementName, Object parameterObject,
String keyProperty) throws SQLException {
return client.queryForMap(statementName, parameterObject, keyProperty);
}
public Map<?, ?> executeQueryForMap(String statementName, Object parameterObject,
String keyProperty, String valueProperty) throws SQLException {
return client.queryForMap(statementName, parameterObject, keyProperty,
valueProperty);
}
public List<?> executeQueryForList(String statementName, Object parameterObject)
throws SQLException {
return client.queryForList(statementName, parameterObject);
}
public List<?> executeQueryForList(String statementName,
Object parameterObject, int skipResults, int maxResults)
throws SQLException {
return client.queryForList(statementName, parameterObject, skipResults,
maxResults);
}
public void executeQueryWithRowHandler(String statementName,
Object parameterObject, RowHandler rowHandler) throws SQLException {
client.queryWithRowHandler(statementName, parameterObject, rowHandler);
}
public void startBatch() throws SQLException {
client.startBatch();
}
public void endBatch() throws SQLException {
client.executeBatch();
}
public DataSource getDataSource() {
return client.getDataSource();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?