List of usage examples for java.sql SQLWarning getMessage
public String getMessage()
From source file:com.oracle.tutorial.jdbc.JDBCTutorialUtilities.java
public static void printWarnings(SQLWarning warning) throws SQLException { if (warning != null) { System.out.println("\n---Warning---\n"); while (warning != null) { System.out.println("Message: " + warning.getMessage()); System.out.println("SQLState: " + warning.getSQLState()); System.out.print("Vendor error code: "); System.out.println(warning.getErrorCode()); System.out.println(""); warning = warning.getNextWarning(); }/*from ww w . j a v a2s. c o m*/ } }
From source file:com.xqdev.sql.MLSQL.java
private static void addWarnings(Element meta, SQLWarning w) { if (w == null) return;/*from w w w . j ava 2 s .co m*/ Namespace sql = meta.getNamespace(); Element warnings = new Element("warnings", sql); meta.addContent(warnings); do { warnings.addContent(new Element("warning", sql).setAttribute("type", w.getClass().getName()) .addContent(new Element("reason", sql).setText(w.getMessage())) .addContent(new Element("sql-state", sql).setText(w.getSQLState())) .addContent(new Element("vendor-code", sql).setText("" + w.getErrorCode()))); w = w.getNextWarning(); } while (w != null); }
From source file:edu.lternet.pasta.doi.DOIScannerTest.java
private static Connection getConnection() throws Exception { Connection conn = null;//w w w. j a va 2s . c o m SQLWarning warn; Class.forName(dbDriver); // Make the database connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword); // If a SQLWarning object is available, print its warning(s). // There may be multiple warnings chained. warn = conn.getWarnings(); if (warn != null) { while (warn != null) { System.err.println("SQLState: " + warn.getSQLState()); System.err.println("Message: " + warn.getMessage()); System.err.println("Vendor: " + warn.getErrorCode()); warn = warn.getNextWarning(); } } return conn; }
From source file:it.unibas.spicy.model.algebra.query.operators.sql.ExecuteSQL.java
public void executeScript(MappingTask mappingTask, AccessConfiguration accessConfiguration, String sqlScript, Reader sourceSQLScriptReader, Reader sourceInstanceSQLScriptReader, Reader targetSQLScriptReader, Reader intermediateSQLScriptReader, int scenarioNo) throws DAOException { boolean isChainingScenario = (mappingTask.getSourceProxy() instanceof ChainingDataSourceProxy); IConnectionFactory connectionFactory = null; Connection connection = null; try {// ww w. j a v a 2 s .c o m connectionFactory = new SimpleDbConnectionFactory(); connection = connectionFactory.getConnection(accessConfiguration); ScriptRunner scriptRunner = new ScriptRunner(connection, true, true); scriptRunner.setLogWriter(null); //giannisk if (sourceSQLScriptReader != null && sourceInstanceSQLScriptReader != null && targetSQLScriptReader != null) { StringBuilder createSchemasQuery = new StringBuilder(); createSchemasQuery .append("create schema " + SpicyEngineConstants.SOURCE_SCHEMA_NAME + scenarioNo + ";\n"); createSchemasQuery .append("create schema " + SpicyEngineConstants.TARGET_SCHEMA_NAME + scenarioNo + ";\n"); //createSchemasQuery.append("create schema " + GenerateSQL.WORK_SCHEMA_NAME + ";\n"); scriptRunner.runScript(new StringReader(createSchemasQuery.toString())); Reader sourceSchemaScript = getSourceSchemaReader(); Reader targetSchemaScript = getTargetSchemaReader(); scriptRunner.runScript(sourceSchemaScript); scriptRunner.runScript(sourceSQLScriptReader); scriptRunner.runScript(sourceInstanceSQLScriptReader); scriptRunner.runScript(targetSchemaScript); scriptRunner.runScript(targetSQLScriptReader); } if (isChainingScenario) { scriptRunner.runScript( new StringReader("create schema " + GenerateSQL.INTERMEDIATE_SCHEMA_NAME + ";\n")); Reader intermediateSchemaScript = getIntermediateSchemaReader(); scriptRunner.runScript(intermediateSchemaScript); scriptRunner.runScript(intermediateSQLScriptReader); } Statement statement = connection.createStatement(); System.out.println("Starting Data Translation" + new java.util.Date()); statement.execute(sqlScript); System.out.println("Data Translation Ended with " + statement.getUpdateCount() + "\t insertions\t" + new java.util.Date()); SQLWarning warning = statement.getWarnings(); String notice = SpicyEngineConstants.PRIMARY_KEY_CONSTR_NOTICE; while (warning != null) { if (warning.getMessage().startsWith(notice)) { String tempTableName = warning.getMessage() .substring(warning.getMessage().lastIndexOf(notice) + notice.length()).trim(); pkConstraintsTableNames.add(tempTableName); } warning = warning.getNextWarning(); } ////Reader sqlReader = new StringReader(sqlScript); /////scriptRunner.runScript(sqlReader); } catch (Exception ex) { logger.error(ex); throw new DAOException(ex); } finally { connectionFactory.close(connection); try { if (sourceSQLScriptReader != null && sourceInstanceSQLScriptReader != null && targetSQLScriptReader != null) { sourceSQLScriptReader.close(); sourceInstanceSQLScriptReader.close(); targetSQLScriptReader.close(); } } catch (IOException ex) { logger.error("Unable to close readers..." + ex); } } //return loadInstance(mappingTask, accessConfiguration, scenarioNo); }
From source file:com.tesora.dve.common.DBHelper.java
public int getNumWarnings() throws SQLException { int count = 0; if (stmt != null) { SQLWarning warning = stmt.getWarnings(); while (warning != null) { // TODO: filter for our test code until SHOW is completely fixed if (!StringUtils.equalsIgnoreCase(warning.getMessage(), "SHOW WARNINGS is not supported")) { count++;/*from ww w. j av a2 s. c o m*/ } warning = warning.getNextWarning(); } return count; } return 0; }
From source file:edu.lternet.pasta.token.TokenManager.java
/** * Returns a connection to the database. * * @return The database Connection object. *//*from w w w .j a va 2 s . c o m*/ private Connection getConnection() throws ClassNotFoundException { Connection conn = null; SQLWarning warn; // Load the jdbc driver. try { Class.forName(this.dbDriver); } catch (ClassNotFoundException e) { logger.error("Can't load driver " + e.getMessage()); throw (e); } // Make the database connection try { conn = DriverManager.getConnection(this.dbURL, this.dbUser, this.dbPassword); // If a SQLWarning object is available, print its warning(s). // There may be multiple warnings chained. warn = conn.getWarnings(); if (warn != null) { while (warn != null) { logger.warn("SQLState: " + warn.getSQLState()); logger.warn("Message: " + warn.getMessage()); logger.warn("Vendor: " + warn.getErrorCode()); warn = warn.getNextWarning(); } } } catch (SQLException e) { logger.error("Database access failed " + e); } return conn; }
From source file:cc.tooyoung.common.db.JdbcTemplate.java
/** * Throw an SQLWarningException if we're not ignoring warnings, * else log the warnings (at debug level). * @param stmt the current JDBC statement * @throws SQLWarningException if not ignoring warnings * @see org.springframework.jdbc.SQLWarningException *//*from ww w . j a v a2s.c om*/ protected void handleWarnings(Statement stmt) throws SQLException { if (isIgnoreWarnings()) { if (ApiLogger.isTraceEnabled()) { SQLWarning warningToLog = stmt.getWarnings(); while (warningToLog != null) { ApiLogger.trace("SQLWarning ignored: SQL state '" + warningToLog.getSQLState() + "', error code '" + warningToLog.getErrorCode() + "', message [" + warningToLog.getMessage() + "]"); warningToLog = warningToLog.getNextWarning(); } } } else { handleWarnings(stmt.getWarnings()); } }
From source file:lib.JdbcTemplate.java
/** * Throw an SQLWarningException if we're not ignoring warnings, * else log the warnings (at debug level). * @param stmt the current JDBC statement * @throws SQLWarningException if not ignoring warnings * @see org.springframework.jdbc.SQLWarningException *///from ww w . j av a2s .c om protected void handleWarnings(Statement stmt) throws SQLException { if (isIgnoreWarnings()) { if (logger.isDebugEnabled()) { SQLWarning warningToLog = stmt.getWarnings(); while (warningToLog != null) { logger.debug("SQLWarning ignored: SQL state '" + warningToLog.getSQLState() + "', error code '" + warningToLog.getErrorCode() + "', message [" + warningToLog.getMessage() + "]"); warningToLog = warningToLog.getNextWarning(); } } } else { handleWarnings(stmt.getWarnings()); } }
From source file:nl.nn.adapterframework.util.JdbcUtil.java
public static XmlBuilder warningsToXmlBuilder(SQLWarning warnings) { if (warnings != null) { XmlBuilder warningsElem = new XmlBuilder("warnings"); while (warnings != null) { XmlBuilder warningElem = new XmlBuilder("warning"); warningElem.addAttribute("errorCode", "" + warnings.getErrorCode()); warningElem.addAttribute("sqlState", "" + warnings.getSQLState()); String message = warnings.getMessage(); // getCause() geeft unresolvedCompilationProblem (bij Peter Leeuwenburgh?) Throwable cause = warnings.getCause(); if (cause != null) { warningElem.addAttribute("cause", cause.getClass().getName()); if (message == null) { message = cause.getMessage(); } else { message = message + ": " + cause.getMessage(); }// w w w. j ava2s . c o m } warningElem.addAttribute("message", message); warningsElem.addSubElement(warningElem); warnings = warnings.getNextWarning(); } return warningsElem; } return null; }
From source file:org.apache.bigtop.itest.hive.TestJdbc.java
/** * Test simple non-statement related class. setSchema is tested elsewhere because there's work * to do for that one. Similarly with getMetadata. * * @throws SQLException/*from w w w . j a va 2 s. com*/ */ @Test public void nonStatementCalls() throws SQLException { conn.clearWarnings(); boolean isAutoCommit = conn.getAutoCommit(); LOG.debug("Auto commit is " + isAutoCommit); String catalog = conn.getCatalog(); LOG.debug("Catalog is " + catalog); String schema = conn.getSchema(); LOG.debug("Schema is " + schema); int txnIsolation = conn.getTransactionIsolation(); LOG.debug("Transaction Isolation is " + txnIsolation); SQLWarning warning = conn.getWarnings(); while (warning != null) { LOG.debug("Found a warning: " + warning.getMessage()); warning = warning.getNextWarning(); } boolean closed = conn.isClosed(); LOG.debug("Is closed? " + closed); boolean readOnly = conn.isReadOnly(); LOG.debug("Is read only?" + readOnly); // Hive doesn't support catalogs, so setting this to whatever should be fine. If we have // non-Hive systems trying to pass this setting it to a non-valid catalog name may cause // issues, so we may need to make this value configurable or something. conn.setCatalog("fred"); }