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


Java JdbcConnection.createStatement方法代码示例

本文整理汇总了Java中liquibase.database.jvm.JdbcConnection.createStatement方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcConnection.createStatement方法的具体用法?Java JdbcConnection.createStatement怎么用?Java JdbcConnection.createStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在liquibase.database.jvm.JdbcConnection的用法示例。


在下文中一共展示了JdbcConnection.createStatement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dropConstraint

import liquibase.database.jvm.JdbcConnection; //导入方法依赖的package包/类
private void dropConstraint(JdbcConnection jdbcConnection, String constraintName) throws Exception {
    Statement statement = null;

    try {
        statement = jdbcConnection.createStatement();
        String dropQuery = String.format(DROP_QUERY, constraintName);
        statement.execute(dropQuery);
        logger.info(String.format("Executed statement '%s'.", dropQuery));
    } finally {
        JdbcUtil.closeQuietly(statement);
    }
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:13,代码来源:DropConfigurationRegistryUniqueConstraint.java

示例2: execute

import liquibase.database.jvm.JdbcConnection; //导入方法依赖的package包/类
@Override
public void execute(Database database) throws CustomChangeException
{
   try
   {
      JdbcConnection connection = (JdbcConnection) database.getConnection();

      // count number of deleted products
      String sql_count = "SELECT COUNT(*) FROM DELETED_PRODUCTS";
      long max;
      try (PreparedStatement stmt = connection.prepareStatement(sql_count))
      {
         ResultSet result = stmt.executeQuery();
         if (!result.next())
         {
            throw new CustomChangeException("DELETED_PRODUCTS table update failed");
         }
         max = result.getLong(1);
      }
      LOGGER.info("{} deleted product(s) to update", max);

      long index = 0;
      String get_pattern = "SELECT ID, CHECKSUMS FROM DELETED_PRODUCTS LIMIT %d,%d";
      String update_pattern = "UPDATE DELETED_PRODUCTS SET CHECKSUM_ALGORITHM='%s', CHECKSUM_VALUE='%s' WHERE ID=%d";
      while (index < max)
      {
         // retrieve data
         sql_count = String.format(get_pattern, index, PAGE_SIZE);
         try (PreparedStatement get_stmt = connection.prepareStatement(sql_count))
         {
            ResultSet get_result = get_stmt.executeQuery();
            Statement batchUpdate = connection.createStatement();
            while (get_result.next())
            {
               // retrieve data
               long id = get_result.getLong("ID");
               Blob blob = get_result.getBlob("CHECKSUMS");
               byte[] data = blob.getBytes(1, (int) blob.length());
               Map<String, String> checksums = (Map<String, String>) deserialize(data);

               if (!checksums.isEmpty())
               {
                  // fill newly fill
                  Map.Entry<String, String> checksum = checksums.entrySet().iterator().next();
                  String sql_update = String.format(update_pattern, checksum.getKey(), checksum.getValue(), id);
                  batchUpdate.addBatch(sql_update);
               }
               index++;
            }
            batchUpdate.executeBatch();
            batchUpdate.close();
            LOGGER.info("RemoveDeletedProductBlobFields:retrieveChecksum: {}/{}", index, max);
         }
      }
   }
   catch (DatabaseException | SQLException | IOException | ClassNotFoundException e)
   {
      throw new CustomChangeException("DELETED_PRODUCTS table update failed", e);
   }
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:61,代码来源:RemoveDeletedProductBlobFields.java

示例3: execute

import liquibase.database.jvm.JdbcConnection; //导入方法依赖的package包/类
@Override
public void execute (Database database) throws CustomChangeException
{
   try
   {
      JdbcConnection jdbc = (JdbcConnection) database.getConnection ();
      String sql;
      Statement statement;
      ResultSet resultSet;

      // Retrieve unencrypted user password
      sql = "SELECT LOGIN, PASSWORD FROM USERS " +
            "WHERE PASSWORD_ENCRYPTION = 'NONE'";
      statement = jdbc.createStatement ();
      HashMap<String, String> unencrypted_user = new HashMap<> ();
      resultSet = statement.executeQuery (sql);
      while (resultSet.next ())
      {
         unencrypted_user.put (resultSet.getString ("LOGIN"),
               resultSet.getString ("PASSWORD"));
      }
      resultSet.close ();
      statement.close ();

      // Encrypt user password and update user
      MessageDigest md = MessageDigest.getInstance ("MD5");
      sql = "UPDATE USERS SET PASSWORD_ENCRYPTION = 'MD5', PASSWORD = '%s'" +
            " WHERE LOGIN = '%s'";
      String query;
      String password;
      for (String login : unencrypted_user.keySet ())
      {
         password = unencrypted_user.get (login);
         password = new String (
               Hex.encode (md.digest (password.getBytes ("UTF-8"))));
         query = String.format (sql, password, login);
         statement = jdbc.createStatement ();
         int updated =  statement.executeUpdate (query);
         if (updated != 1)
         {
            LOGGER.warn(updated + " encryption update perform on user : " + login);
         }
         statement.close ();
      }
      unencrypted_user.clear ();
   }
   catch (Exception e)
   {
      throw new CustomChangeException (
            "An error occurred during forceEncryptPassword changelog", e);
   }
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:53,代码来源:ForceEncryptPassword.java


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