/** * "Guess" the {@link SQLDialect} from a {@link Connection} instance. * <p> * This method tries to guess the <code>SQLDialect</code> of a connection * from the its connection URL as obtained by * {@link DatabaseMetaData#getURL()}. If the dialect cannot be guessed from * the URL (e.g. when using an JDBC-ODBC bridge), further actions may be * implemented in the future. * * @see #dialect(String) */ @SuppressWarnings("deprecation") public static final SQLDialect dialect(Connection connection) { SQLDialect result = SQLDialect.SQL99; try { String url = connection.getMetaData().getURL(); result = dialect(url); } catch (SQLException ignore) {} if (result == SQLDialect.SQL99) { // If the dialect cannot be guessed from the URL, take some other // measures, e.g. by querying DatabaseMetaData.getDatabaseProductName() } return result; }
public WpDataSource(DataSource dataSource) throws DaoException { this.settings = new Settings(); this.dataSource = dataSource; Connection conn = null; try { conn = dataSource.getConnection(); this.dialect = JooqUtils.dialect(conn); } catch (SQLException e) { throw new DaoException("SQL Dao Failed. Check if the table exists / if the desired information has been parsed and stored in the database\n" + e.toString()); } finally { closeQuietly(conn); } // Postgres uses a lowercase "public" main schema if (this.dialect == SQLDialect.POSTGRES) { settings.setRenderNameStyle(RenderNameStyle.LOWER); } }
try { conn = wpDs.getConnection(); this.dialect = JooqUtils.dialect(conn); } catch (SQLException e) { throw new DaoException("SQL Dao Failed. Check if the table exists / if the desired information has been parsed and stored in the database\n" + e.toString());