List of usage examples for java.sql Statement getWarnings
SQLWarning getWarnings() throws SQLException;
Statement
object. From source file:Main.java
public static void main(String[] argv) throws Exception { String driverName = "com.jnetdirect.jsql.JSQLDriver"; Class.forName(driverName);// www .ja va 2 s .co m String serverName = "127.0.0.1"; String portNumber = "1433"; String mydatabase = serverName + ":" + portNumber; String url = "jdbc:JSQLConnect://" + mydatabase; String username = "username"; String password = "password"; Connection connection = DriverManager.getConnection(url, username, password); try { SQLWarning warning = connection.getWarnings(); while (warning != null) { String message = warning.getMessage(); String sqlState = warning.getSQLState(); int errorCode = warning.getErrorCode(); warning = warning.getNextWarning(); } Statement stmt = connection.createStatement(); warning = stmt.getWarnings(); if (warning != null) { } ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table"); while (resultSet.next()) { warning = resultSet.getWarnings(); if (warning != null) { } } } catch (SQLException e) { } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySQLConnection(); Statement stmt = null; try {/*from w ww. j a v a2s . c o m*/ stmt = conn.createStatement(); stmt.executeUpdate("DELETE FROM Mytable"); displayError(stmt.getWarnings()); stmt.executeUpdate( "INSERT INTO Mytable(id, name)" + "VALUES(1, 'NameLongerThanColumnLengthInDatabase')"); displayError(stmt.getWarnings()); } catch (DataTruncation dt) { displayError(dt); dt.printStackTrace(); } catch (SQLException se) { System.out.println("Database error message: " + se.getMessage()); } catch (Exception e) { e.printStackTrace(); } finally { stmt.close(); conn.close(); } }
From source file:DemoDataTruncation.java
public static void main(String[] args) throws Exception { Connection conn = getMySQLConnection(); Statement stmt = null; try {//from w w w. j ava 2 s .c om stmt = conn.createStatement(); stmt.executeUpdate("DELETE FROM animals_table"); displayError(stmt.getWarnings()); stmt.executeUpdate( "INSERT INTO animals_table(id, name)" + "VALUES(1, 'NameLongerThanColumnLengthInDatabase')"); displayError(stmt.getWarnings()); } catch (DataTruncation dt) { displayError(dt); dt.printStackTrace(); } catch (SQLException se) { System.out.println("Database error message: " + se.getMessage()); } catch (Exception e) { e.printStackTrace(); } finally { stmt.close(); conn.close(); } }
From source file:SqlWarning.java
public static void main(String[] args) { try {/*w w w . j a v a 2s . c o m*/ Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:ORCL"; Connection conn = DriverManager.getConnection(jdbcUrl, "yourName", "mypwd"); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); SQLWarning sw = null; ResultSet rs = stmt.executeQuery("Select * from employees"); sw = stmt.getWarnings(); System.out.println(sw.getMessage()); while (rs.next()) { System.out.println("Employee name: " + rs.getString(2)); } rs.previous(); rs.updateString("name", "Jon"); } catch (SQLException se) { System.out.println("SQLException occurred: " + se.getMessage()); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); conn.setAutoCommit(false);/* ww w . j ava2s . c o m*/ Statement stmt = conn.createStatement(); stmt.executeUpdate("create table survey (id int, name CHAR(5) );"); stmt.executeUpdate("INSERT INTO survey(id, name)VALUES(111, '123456789')"); displayError(stmt.getWarnings()); // try to write more data for the name column. displayError(stmt.getWarnings()); // since there were no errors, commit conn.commit(); ResultSet rs = stmt.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { // Get warnings on Statement object Connection conn = null;/*from w w w.j a va 2 s. c o m*/ Statement stmt = null; try { conn = getConnection(); // get a java.sql.Connection object stmt = conn.createStatement(); // create a statement // use the statement // get warnings on Statement object SQLWarning warning = stmt.getWarnings(); if (warning != null) { // Process statement warnings } } catch (SQLException e) { // ignore the exception } finally { // close JDBC resources: ResultSet, Statement, Connection } }
From source file:com.oracle.tutorial.jdbc.JDBCTutorialUtilities.java
public static void getWarningsFromStatement(Statement stmt) throws SQLException { JDBCTutorialUtilities.printWarnings(stmt.getWarnings()); }
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 {//from w ww . j ava 2 s .c om 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: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 w w w . jav a 2 s .c o m 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 w ww .j a va 2 s . c o m 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()); } }