Java Code Examples for java.sql.DatabaseMetaData#supportsBatchUpdates()
The following examples show how to use
java.sql.DatabaseMetaData#supportsBatchUpdates() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdbcUtils.java From spring-analysis-note with MIT License | 6 votes |
/** * Return whether the given JDBC driver supports JDBC 2.0 batch updates. * <p>Typically invoked right before execution of a given set of statements: * to decide whether the set of SQL statements should be executed through * the JDBC 2.0 batch mechanism or simply in a traditional one-by-one fashion. * <p>Logs a warning if the "supportsBatchUpdates" methods throws an exception * and simply returns {@code false} in that case. * @param con the Connection to check * @return whether JDBC 2.0 batch updates are supported * @see java.sql.DatabaseMetaData#supportsBatchUpdates() */ public static boolean supportsBatchUpdates(Connection con) { try { DatabaseMetaData dbmd = con.getMetaData(); if (dbmd != null) { if (dbmd.supportsBatchUpdates()) { logger.debug("JDBC driver supports batch updates"); return true; } else { logger.debug("JDBC driver does not support batch updates"); } } } catch (SQLException ex) { logger.debug("JDBC driver 'supportsBatchUpdates' method threw exception", ex); } return false; }
Example 2
Source File: JdbcUtils.java From java-technology-stack with MIT License | 6 votes |
/** * Return whether the given JDBC driver supports JDBC 2.0 batch updates. * <p>Typically invoked right before execution of a given set of statements: * to decide whether the set of SQL statements should be executed through * the JDBC 2.0 batch mechanism or simply in a traditional one-by-one fashion. * <p>Logs a warning if the "supportsBatchUpdates" methods throws an exception * and simply returns {@code false} in that case. * @param con the Connection to check * @return whether JDBC 2.0 batch updates are supported * @see java.sql.DatabaseMetaData#supportsBatchUpdates() */ public static boolean supportsBatchUpdates(Connection con) { try { DatabaseMetaData dbmd = con.getMetaData(); if (dbmd != null) { if (dbmd.supportsBatchUpdates()) { logger.debug("JDBC driver supports batch updates"); return true; } else { logger.debug("JDBC driver does not support batch updates"); } } } catch (SQLException ex) { logger.debug("JDBC driver 'supportsBatchUpdates' method threw exception", ex); } return false; }
Example 3
Source File: JdbcUtils.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Return whether the given JDBC driver supports JDBC 2.0 batch updates. * <p>Typically invoked right before execution of a given set of statements: * to decide whether the set of SQL statements should be executed through * the JDBC 2.0 batch mechanism or simply in a traditional one-by-one fashion. * <p>Logs a warning if the "supportsBatchUpdates" methods throws an exception * and simply returns {@code false} in that case. * @param con the Connection to check * @return whether JDBC 2.0 batch updates are supported * @see java.sql.DatabaseMetaData#supportsBatchUpdates() */ public static boolean supportsBatchUpdates(Connection con) { try { DatabaseMetaData dbmd = con.getMetaData(); if (dbmd != null) { if (dbmd.supportsBatchUpdates()) { logger.debug("JDBC driver supports batch updates"); return true; } else { logger.debug("JDBC driver does not support batch updates"); } } } catch (SQLException ex) { logger.debug("JDBC driver 'supportsBatchUpdates' method threw exception", ex); } return false; }
Example 4
Source File: ExtractedDatabaseMetaDataImpl.java From lams with GNU General Public License v2.0 | 6 votes |
public Builder apply(DatabaseMetaData databaseMetaData) throws SQLException { connectionCatalogName = databaseMetaData.getConnection().getCatalog(); // NOTE : databaseMetaData.getConnection().getSchema() would require java 1.7 as baseline supportsRefCursors = StandardRefCursorSupport.supportsRefCursors( databaseMetaData ); supportsNamedParameters = databaseMetaData.supportsNamedParameters(); supportsScrollableResults = databaseMetaData.supportsResultSetType( ResultSet.TYPE_SCROLL_INSENSITIVE ); supportsGetGeneratedKeys = databaseMetaData.supportsGetGeneratedKeys(); supportsBatchUpdates = databaseMetaData.supportsBatchUpdates(); supportsDataDefinitionInTransaction = !databaseMetaData.dataDefinitionIgnoredInTransactions(); doesDataDefinitionCauseTransactionCommit = databaseMetaData.dataDefinitionCausesTransactionCommit(); extraKeywords = parseKeywords( databaseMetaData.getSQLKeywords() ); sqlStateType = SQLStateType.interpretReportedSQLStateType( databaseMetaData.getSQLStateType() ); lobLocatorUpdateCopy = databaseMetaData.locatorsUpdateCopy(); typeInfoSet = new LinkedHashSet<TypeInfo>(); typeInfoSet.addAll( TypeInfo.extractTypeInfo( databaseMetaData ) ); return this; }
Example 5
Source File: JdbcUtils.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Return whether the given JDBC driver supports JDBC 2.0 batch updates. * <p>Typically invoked right before execution of a given set of statements: * to decide whether the set of SQL statements should be executed through * the JDBC 2.0 batch mechanism or simply in a traditional one-by-one fashion. * <p>Logs a warning if the "supportsBatchUpdates" methods throws an exception * and simply returns {@code false} in that case. * @param con the Connection to check * @return whether JDBC 2.0 batch updates are supported * @see java.sql.DatabaseMetaData#supportsBatchUpdates() */ public static boolean supportsBatchUpdates(Connection con) { try { DatabaseMetaData dbmd = con.getMetaData(); if (dbmd != null) { if (dbmd.supportsBatchUpdates()) { logger.debug("JDBC driver supports batch updates"); return true; } else { logger.debug("JDBC driver does not support batch updates"); } } } catch (SQLException ex) { logger.debug("JDBC driver 'supportsBatchUpdates' method threw exception", ex); } return false; }
Example 6
Source File: EntityDataStore.java From requery with Apache License 2.0 | 6 votes |
protected void checkConnectionMetadata() { synchronized (configuration) { // only done once metadata assumed to be the same for every connection if (!metadataChecked) { try (Connection connection = context.getConnection()) { DatabaseMetaData metadata = connection.getMetaData(); if (!metadata.supportsTransactions()) { transactionMode = TransactionMode.NONE; } supportsBatchUpdates = metadata.supportsBatchUpdates(); String quoteIdentifier = metadata.getIdentifierQuoteString(); queryOptions = new QueryBuilder.Options(quoteIdentifier, true, configuration.getTableTransformer(), configuration.getColumnTransformer(), configuration.getQuoteTableNames(), configuration.getQuoteColumnNames()); metadataChecked = true; } catch (SQLException e) { throw new PersistenceException(e); } } } }
Example 7
Source File: JdbcUtils.java From effectivejava with Apache License 2.0 | 6 votes |
/** * Return whether the given JDBC driver supports JDBC 2.0 batch updates. * <p>Typically invoked right before execution of a given set of statements: * to decide whether the set of SQL statements should be executed through * the JDBC 2.0 batch mechanism or simply in a traditional one-by-one fashion. * <p>Logs a warning if the "supportsBatchUpdates" methods throws an exception * and simply returns {@code false} in that case. * @param con the Connection to check * @return whether JDBC 2.0 batch updates are supported * @see java.sql.DatabaseMetaData#supportsBatchUpdates() */ public static boolean supportsBatchUpdates(Connection con) { try { DatabaseMetaData dbmd = con.getMetaData(); if (dbmd != null) { if (dbmd.supportsBatchUpdates()) { logger.debug("JDBC driver supports batch updates"); return true; } else { logger.debug("JDBC driver does not support batch updates"); } } } catch (SQLException ex) { logger.debug("JDBC driver 'supportsBatchUpdates' method threw exception", ex); } return false; }
Example 8
Source File: JdbcDatabaseManager.java From logging-log4j2 with Apache License 2.0 | 6 votes |
private void connectAndPrepare() throws SQLException { logger().debug("Acquiring JDBC connection from {}", this.getConnectionSource()); this.connection = getConnectionSource().getConnection(); logger().debug("Acquired JDBC connection {}", this.connection); logger().debug("Getting connection metadata {}", this.connection); final DatabaseMetaData databaseMetaData = this.connection.getMetaData(); logger().debug("Connection metadata {}", databaseMetaData); this.isBatchSupported = databaseMetaData.supportsBatchUpdates(); logger().debug("Connection supportsBatchUpdates: {}", this.isBatchSupported); this.connection.setAutoCommit(false); logger().debug("Preparing SQL {}", this.sqlStatement); this.statement = this.connection.prepareStatement(this.sqlStatement); logger().debug("Prepared SQL {}", this.statement); if (this.factoryData.truncateStrings) { initColumnMetaData(); } }
Example 9
Source File: DbConnectionManager.java From Openfire with Apache License 2.0 | 4 votes |
/** * Uses a connection from the database to set meta data information about * what different JDBC drivers and databases support. * * @param con the connection. * @throws SQLException if an SQL exception occurs. */ private static void setMetaData(Connection con) throws SQLException { DatabaseMetaData metaData = con.getMetaData(); // Supports transactions? transactionsSupported = metaData.supportsTransactions(); // Supports subqueries? subqueriesSupported = metaData.supportsCorrelatedSubqueries(); // Supports scroll insensitive result sets? Try/catch block is a // workaround for DB2 JDBC driver, which throws an exception on // the method call. try { scrollResultsSupported = metaData.supportsResultSetType( ResultSet.TYPE_SCROLL_INSENSITIVE); } catch (Exception e) { scrollResultsSupported = false; } // Supports batch updates batchUpdatesSupported = metaData.supportsBatchUpdates(); // Set defaults for other meta properties streamTextRequired = false; maxRowsSupported = true; fetchSizeSupported = true; identifierQuoteString = metaData.getIdentifierQuoteString(); // Get the database name so that we can perform meta data settings. String dbName = metaData.getDatabaseProductName().toLowerCase(); String driverName = metaData.getDriverName().toLowerCase(); // Oracle properties. if (dbName.indexOf("oracle") != -1) { databaseType = DatabaseType.oracle; streamTextRequired = true; scrollResultsSupported = false; /* TODO comment and test this, it should be supported since 10g */ // The i-net AUGURO JDBC driver if (driverName.indexOf("auguro") != -1) { streamTextRequired = false; fetchSizeSupported = true; maxRowsSupported = false; } } // Postgres properties else if (dbName.indexOf("postgres") != -1) { databaseType = DatabaseType.postgresql; // Postgres blows, so disable scrolling result sets. scrollResultsSupported = false; fetchSizeSupported = false; } // Interbase properties else if (dbName.indexOf("interbase") != -1) { databaseType = DatabaseType.interbase; fetchSizeSupported = false; maxRowsSupported = false; } // SQLServer else if (dbName.indexOf("sql server") != -1) { databaseType = DatabaseType.sqlserver; // JDBC driver i-net UNA properties if (driverName.indexOf("una") != -1) { fetchSizeSupported = true; maxRowsSupported = false; } } // MySQL properties else if (dbName.indexOf("mysql") != -1) { databaseType = DatabaseType.mysql; transactionsSupported = false; /* TODO comment and test this, it should be supported since 5.0 */ } // HSQL properties else if (dbName.indexOf("hsql") != -1) { databaseType = DatabaseType.hsqldb; // scrollResultsSupported = false; /* comment and test this, it should be supported since 1.7.2 */ } // DB2 properties. else if (dbName.indexOf("db2") != 1) { databaseType = DatabaseType.db2; } }