本文整理汇总了Java中org.seasar.extension.jdbc.util.ConnectionUtil.close方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionUtil.close方法的具体用法?Java ConnectionUtil.close怎么用?Java ConnectionUtil.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.seasar.extension.jdbc.util.ConnectionUtil
的用法示例。
在下文中一共展示了ConnectionUtil.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
/**
* SQLを実行します。
*/
public void execute() {
System.out.println(sql);
Connection connection = org.seasar.extension.jdbc.util.DataSourceUtil
.getConnection(implementor.getDataSource());
try {
PreparedStatement ps = ConnectionUtil.prepareStatement(
connection, sql);
try {
PreparedStatementUtil.execute(ps);
} finally {
StatementUtil.close(ps);
}
} finally {
ConnectionUtil.close(connection);
}
}
示例2: exportSchema
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
@Override
public void exportSchema(ExportParams params) throws MojoExecutionException {
Connection conn = null;
try {
File dumpFile = params.getDumpFile();
String user = params.getUser();
String password = params.getPassword();
conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
stmt.execute("SCRIPT DROP TO '" + dumpFile.getAbsolutePath()+ "'");
StatementUtil.close(stmt);
} catch (SQLException e) {
throw new MojoExecutionException("Schema export実行中にエラー", e);
} finally {
ConnectionUtil.close(conn);
}
}
示例3: importSchema
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
@Override
public void importSchema(ImportParams params) throws MojoExecutionException {
Connection conn = null;
try {
File dumpFile = params.getDumpFile();
if (!dumpFile.exists())
throw new MojoExecutionException(dumpFile.getName() + " is not found?");
String user = params.getAdminUser();
String password = params.getAdminPassword();
conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
stmt.execute("RUNSCRIPT FROM '" + dumpFile.getAbsolutePath()+ "'");
StatementUtil.close(stmt);
} catch (Exception e) {
throw new MojoExecutionException("Schema import実行中にエラー", e);
} finally {
ConnectionUtil.close(conn);
}
}
示例4: createUser
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
@Override
public void createUser(String user, String password, String adminUser,
String adminPassword) throws MojoExecutionException {
Connection conn = null;
Statement stmt = null;
try {
conn = DriverManager.getConnection(url, adminUser, adminPassword);
stmt = conn.createStatement();
stmt.execute("CREATE USER IF NOT EXISTS " + user + " PASSWORD '" + password + "'" + " ADMIN");
} catch (SQLException e) {
throw new MojoExecutionException("CREATE USER 実行中にエラー: ", e);
} finally {
StatementUtil.close(stmt);
ConnectionUtil.close(conn);
}
}
示例5: createUser
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
@Override
public void createUser(String user, String password, String adminUser,
String adminPassword) throws MojoExecutionException {
Connection conn = null;
Statement stmt = null;
try {
conn = DriverManager.getConnection(url, adminUser, adminPassword);
stmt = conn.createStatement();
if(existsUser(adminUser, adminPassword, user)) {
return;
}
stmt.execute("CREATE LOGIN " + user + " WITH PASSWORD = '" + password + "'");
stmt.execute("CREATE USER " + user + " FOR LOGIN " + user);
stmt.execute("sp_addrolemember 'db_ddladmin','" + user + "'");
} catch (SQLException e) {
throw new MojoExecutionException("CREATE USER実行中にエラー", e);
} finally {
StatementUtil.close(stmt);
ConnectionUtil.close(conn);
}
}
示例6: existsUser
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
private boolean existsUser(String adminUser, String adminPassword, String user) throws SQLException {
Connection conn = null;
PreparedStatement stmt = null;
boolean existLogin = false;
boolean existUser = false;
try {
conn = DriverManager.getConnection(getUrlReplaceDatabaseName("master"), adminUser, adminPassword);
stmt = conn.prepareStatement("SELECT COUNT(*) AS num FROM syslogins WHERE name = ?");
stmt.setString(1, user);
existLogin = exists(stmt.executeQuery());
ConnectionUtil.close(conn);
conn = DriverManager.getConnection(url, adminUser, adminPassword);
stmt = conn.prepareStatement("SELECT COUNT(*) AS num FROM sysusers WHERE name = ?");
stmt.setString(1, user);
existUser = exists(stmt.executeQuery());
} finally {
StatementUtil.close(stmt);
ConnectionUtil.close(conn);
}
return (existLogin && existUser);
}
示例7: createSchema
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
private void createSchema(String schema, String user, String password, String admin, String adminPassword) throws MojoExecutionException {
PreparedStatement userStmt = null;
Statement createUserStmt = null;
Connection conn = null;
try{
conn = DriverManager.getConnection(url, admin, adminPassword);
createUserStmt = conn.createStatement();
createUserStmt.execute("CREATE SCHEMA " + schema + " AUTHORIZATION " + user);
} catch (SQLException e) {
throw new MojoExecutionException("CREATE SCHEMA実行中にエラー", e);
} finally {
StatementUtil.close(userStmt);
StatementUtil.close(createUserStmt);
ConnectionUtil.close(conn);
}
}
示例8: getValueOfSql
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
/**
* 指定されたSQLの値取得
*
* @param sql
* @param url
* @param user
* @param password
* @return カウント
* @throws SQLException
*/
static public <T> T getValueOfSql(String sql, String url, String user, String password) throws SQLException {
Statement stmt = null;
Connection conn = null;
try {
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
rs.next();
return (T) rs.getObject(1);
} catch (Exception e) {
e.printStackTrace();
throw new SQLException("DBTestUtilエラー", "SQLの実行に失敗しました");
} finally {
StatementUtil.close(stmt);
ConnectionUtil.close(conn);
}
}
示例9: createUser
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
@Override
public void createUser(String user, String password, String adminUser, String adminPassword) throws MojoExecutionException{
Connection conn = null;
Statement stmt = null;
try {
conn = DriverManager.getConnection(url, adminUser, adminPassword);
stmt = conn.createStatement();
String db = normalizeSchemaName(conn.getCatalog());
if(existsUser(conn, user)) {
// 既にユーザが存在している場合でも必要な権限を付与しておく。
stmt.execute("GRANT ALL ON " + db + ".* TO '" + user + "'");
return;
}
stmt.execute("CREATE USER '"+ user + "' IDENTIFIED BY '"+ password +"'");
stmt.execute("GRANT ALL ON " + db + ".* TO '" + user + "'");
} catch (SQLException e) {
throw new MojoExecutionException("CREATE USER実行中にエラー", e);
} finally {
StatementUtil.close(stmt);
ConnectionUtil.close(conn);
}
}
示例10: createUser
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
@Override
public void createUser(String user, String password, String adminUser,
String adminPassword) throws MojoExecutionException {
Connection conn = null;
Statement stmt = null;
String database = getDatabase();
String role = StringUtils.lowerCase(user);
try {
conn = DriverManager.getConnection(url, adminUser, adminPassword);
stmt = conn.createStatement();
if (existsUser(conn, role)) {
return;
}
stmt.execute("CREATE ROLE " + role + " LOGIN PASSWORD \'" + password + "\'");
stmt.execute("GRANT CREATE, CONNECT ON DATABASE " + database + " TO " + role);
} catch (SQLException e) {
throw new MojoExecutionException("CREATE USER実行中にエラー", e);
} finally {
StatementUtil.close(stmt);
ConnectionUtil.close(conn);
}
}
示例11: getCount
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
/**
* 指定されたSQLの件数取得
*
* @param sql
* @param url
* @param user
* @param password
* @return カウント
* @throws SQLException
*/
static public int getCount(String sql, String url, String user, String password) throws SQLException {
Statement stmt = null;
Connection conn = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
rs.next();
return rs.getInt(1);
} catch (Exception e) {
e.printStackTrace();
throw new SQLException("DBTestUtilエラー", "件数カウントに失敗しました");
} finally {
ResultSetUtil.close(rs);
StatementUtil.close(stmt);
ConnectionUtil.close(conn);
}
}
示例12: initialize
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
public void initialize() {
beanClass = daoAnnotationReader.getBeanClass();
daoInterface = getDaoInterface(daoClass);
daoBeanDesc = BeanDescFactory.getBeanDesc(daoClass);
final Connection con = DataSourceUtil.getConnection(dataSource);
try {
final DatabaseMetaData dbMetaData = ConnectionUtil.getMetaData(con);
dbms = DbmsManager.getDbms(dbMetaData);
} finally {
ConnectionUtil.close(con);
}
this.beanMetaData = beanMetaDataFactory.createBeanMetaData(
daoInterface, beanClass);
checkSingleRowUpdateForAll = daoAnnotationReader
.isCheckSingleRowUpdate();
setupSqlCommand();
}
示例13: execute
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
public int[] execute(List list) throws SQLRuntimeException {
if (list == null) {
throw new IllegalArgumentException("list");
}
Connection connection = getConnection();
try {
PreparedStatement ps = prepareStatement(connection);
try {
for (Iterator iter = list.iterator(); iter.hasNext();) {
Object bean = (Object) iter.next();
execute(ps, bean);
}
return PreparedStatementUtil.executeBatch(ps);
} finally {
StatementUtil.close(ps);
}
} finally {
ConnectionUtil.close(connection);
}
}
示例14: dropAll
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
/**
* GSPではPUBLICスキーマしか対応していないのでスキーマの生成は不要。
*
*/
@Override
public void dropAll(String user, String password, String adminUser,
String adminPassword, String schema) throws MojoExecutionException {
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = DriverManager.getConnection(url, adminUser, adminPassword);
// スキーマ内のテーブル、ビュー、シーケンス削除
String nmzschema = normalizeSchemaName(schema);
String dropListSql = "SELECT TABLE_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.CONSTRAINTS WHERE CONSTRAINT_SCHEMA='" + nmzschema + "'";
dropObjectsInSchema(conn, dropListSql, nmzschema, OBJECT_TYPE.FK);
dropListSql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA='" + nmzschema + "'";
dropObjectsInSchema(conn, dropListSql, nmzschema, OBJECT_TYPE.VIEW);
dropListSql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='" + nmzschema + "'";
dropObjectsInSchema(conn, dropListSql, nmzschema, OBJECT_TYPE.TABLE);
} catch (SQLException e) {
throw new MojoExecutionException("DROP ALL実行中にエラー", e);
} finally {
StatementUtil.close(pstmt);
ConnectionUtil.close(conn);
}
}
示例15: dropAll
import org.seasar.extension.jdbc.util.ConnectionUtil; //导入方法依赖的package包/类
@Override
public void dropAll(String user, String password, String adminUser,
String adminPassword, String schema) throws MojoExecutionException {
Connection conn = null;
Statement stmt = null;
try {
conn = DriverManager.getConnection(url, adminUser, adminPassword);
stmt = conn.createStatement();
// 指定スキーマがいなければ作成する。
if(!existsSchema(conn, schema)) {
createSchema(schema, user, password, adminUser, adminPassword);
return;
} else {
// 指定スキーマが存在する場合はスキーマ操作権限を念のため与えておく
stmt.execute("GRANT CREATEIN,ALTERIN,DROPIN ON SCHEMA " + schema + " TO USER " + user);
}
// スキーマ内のテーブル、ビュー、シーケンス削除
String nmzschema = normalizeSchemaName(schema);
String dropListSql = "SELECT TABNAME, CONSTNAME FROM SYSCAT.TABCONST WHERE TYPE='F' AND TABSCHEMA='" + nmzschema + "'";
dropObjectsInSchema(conn, dropListSql, nmzschema, OBJECT_TYPE.FK);
dropListSql = "SELECT TABNAME FROM SYSCAT.TABLES WHERE OWNERTYPE='U' AND TYPE IN('V') AND TABSCHEMA='" + nmzschema + "'";
dropObjectsInSchema(conn, dropListSql, nmzschema, OBJECT_TYPE.VIEW);
dropListSql = "SELECT TABNAME FROM SYSCAT.TABLES WHERE OWNERTYPE='U' AND TYPE IN('T') AND TABSCHEMA='" + nmzschema + "'";
dropObjectsInSchema(conn, dropListSql, nmzschema, OBJECT_TYPE.TABLE);
} catch (SQLException e) {
throw new MojoExecutionException("データ削除中にエラー", e);
} finally {
StatementUtil.close(stmt);
ConnectionUtil.close(conn);
}
}