当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionUtil类代码示例

本文整理汇总了Java中org.seasar.extension.jdbc.util.ConnectionUtil的典型用法代码示例。如果您正苦于以下问题:Java ConnectionUtil类的具体用法?Java ConnectionUtil怎么用?Java ConnectionUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionUtil类属于org.seasar.extension.jdbc.util包,在下文中一共展示了ConnectionUtil类的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);
    }
}
 
开发者ID:kagucho,项目名称:tsubonesystem2,代码行数:20,代码来源:SqlFileTest.java

示例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);
    }
}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:19,代码来源:H2Dialect.java

示例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);
    }
}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:23,代码来源:H2Dialect.java

示例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);
    }
}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:17,代码来源:H2Dialect.java

示例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);
    }
}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:23,代码来源:SqlserverDialect.java

示例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);
}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:22,代码来源:SqlserverDialect.java

示例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);
}
  }
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:19,代码来源:Db2Dialect.java

示例8: 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);
	}
}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:24,代码来源:MysqlDialect.java

示例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;
    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);
    }
}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:24,代码来源:PostgresqlDialect.java

示例10: 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);
	}

}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:32,代码来源:DBTestUtil.java

示例11: 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);
	}
}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:29,代码来源:DBTestUtil.java

示例12: selectSimpleBinary

import org.seasar.extension.jdbc.util.ConnectionUtil; //导入依赖的package包/类
/**
 * 
 * 
 * @param sql
 * @param file
 * @param url
 * @param user
 * @param password
 */
static public void selectSimpleBinary(String sql, File file, String url, String user, String password) {

	PreparedStatement psmt = null;
	ResultSet rset = null;
	Connection conn = null;
	try {
		conn = DriverManager.getConnection(url, user, password);
		psmt = conn.prepareStatement(sql);
		rset = psmt.executeQuery();
		rset.getBinaryStream(1);
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		StatementUtil.close(psmt);
		ConnectionUtil.close(conn);
	}
}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:27,代码来源:DBTestUtil.java

示例13: createPreparedStatement

import org.seasar.extension.jdbc.util.ConnectionUtil; //导入依赖的package包/类
public PreparedStatement createPreparedStatement(Connection con, String sql) {
    /*
     * https://www.seasar.org/issues/browse/DAO-42
     */
    final Object[] args = PagerContext.getContext().peekArgs();
    PreparedStatement pstmt = null;
    if (PagerContext.isPagerCondition(args)) {
        try {
            pstmt = con.prepareStatement(sql,
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
        } catch (SQLException e) {
            throw new SQLRuntimeException(e);
        }
        return createPreparedStatement(pstmt, sql);
    }
    pstmt = ConnectionUtil.prepareStatement(con, sql);
    return createPreparedStatement(pstmt, sql);
}
 
开发者ID:seasarorg,项目名称:s2dao,代码行数:20,代码来源:PagerStatementFactory.java

示例14: 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();
}
 
开发者ID:seasarorg,项目名称:s2dao,代码行数:18,代码来源:DaoMetaDataImpl.java

示例15: 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);
    }
}
 
开发者ID:seasarorg,项目名称:s2dao,代码行数:21,代码来源:AbstractBatchAutoHandler.java


注:本文中的org.seasar.extension.jdbc.util.ConnectionUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。