List of usage examples for java.sql SQLException toString
public String toString()
From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java
@Test public void TestResultSetgetRow() { try {/*from w w w . ja v a 2 s .co m*/ Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(1)); Assert.assertEquals(1, BQResultSetFunctionTest.Result.getRow()); Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(10)); Assert.assertEquals(10, BQResultSetFunctionTest.Result.getRow()); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } try { BQResultSetFunctionTest.Result.beforeFirst(); Assert.assertEquals(0, BQResultSetFunctionTest.Result.getRow()); BQResultSetFunctionTest.Result.afterLast(); Assert.assertEquals(0, BQResultSetFunctionTest.Result.getRow()); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } }
From source file:BQJDBC.QueryResultTest.BQScrollableResultSetFunctionTest.java
/** * For testing isValid() , Close() , isClosed() *//*from ww w .ja v a 2s . com*/ @Test public void isClosedValidtest() { try { Assert.assertEquals(true, BQScrollableResultSetFunctionTest.con.isValid(0)); } catch (SQLException e) { Assert.fail("Got an exception" + e.toString()); e.printStackTrace(); } try { Assert.assertEquals(true, BQScrollableResultSetFunctionTest.con.isValid(10)); } catch (SQLException e) { Assert.fail("Got an exception" + e.toString()); e.printStackTrace(); } try { BQScrollableResultSetFunctionTest.con.isValid(-10); } catch (SQLException e) { Assert.assertTrue(true); // e.printStackTrace(); } try { BQScrollableResultSetFunctionTest.con.close(); } catch (SQLException e) { e.printStackTrace(); } try { Assert.assertTrue(BQScrollableResultSetFunctionTest.con.isClosed()); } catch (SQLException e1) { e1.printStackTrace(); } try { BQScrollableResultSetFunctionTest.con.isValid(0); } catch (SQLException e) { Assert.assertTrue(true); e.printStackTrace(); } }
From source file:BQJDBC.QueryResultTest.BQScrollableResultSetFunctionTest.java
@Test public void TestResultSetPrevious() { try {/*from www . java 2s . com*/ Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.last()); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.previous()); Assert.assertEquals("words", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.previous()); Assert.assertEquals("young", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.previous()); Assert.assertEquals("your", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.previous()); Assert.assertEquals("with", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.previous()); Assert.assertEquals("without", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.previous()); Assert.assertEquals("world", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.previous()); Assert.assertEquals("would", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.previous()); Assert.assertEquals("yet", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.previous()); Assert.assertEquals("you", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertFalse(BQScrollableResultSetFunctionTest.Result.previous()); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } try { Assert.assertEquals("", BQScrollableResultSetFunctionTest.Result.getString(1)); } catch (SQLException e) { boolean ct = e.toString().contains("Cursor is not in a valid Position"); if (ct == true) { Assert.assertTrue(ct); } else { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } } }
From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java
@Test public void TestResultSetAfterlast() { try {//from w w w. j a v a2 s . c om BQResultSetFunctionTest.Result.afterLast(); Assert.assertTrue(BQResultSetFunctionTest.Result.previous()); Assert.assertEquals("word", BQResultSetFunctionTest.Result.getString(1)); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } try { BQResultSetFunctionTest.Result.afterLast(); Assert.assertEquals("", BQResultSetFunctionTest.Result.getString(1)); } catch (SQLException e) { boolean ct = e.toString().contains("Cursor is not in a valid Position"); if (ct == true) { Assert.assertTrue(ct); } else { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } } }
From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java
@Test public void TestResultSetBeforeFirst() { try {/* ww w.ja va 2 s . c o m*/ BQResultSetFunctionTest.Result.beforeFirst(); Assert.assertTrue(BQResultSetFunctionTest.Result.next()); Assert.assertEquals("you", BQResultSetFunctionTest.Result.getString(1)); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } try { BQResultSetFunctionTest.Result.beforeFirst(); Assert.assertEquals("", BQResultSetFunctionTest.Result.getString(1)); } catch (SQLException e) { boolean ct = e.toString().contains("Cursor is not in a valid Position"); if (ct == true) { Assert.assertTrue(ct); } else { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } } }
From source file:BQJDBC.QueryResultTest.BQScrollableResultSetFunctionTest.java
@Test public void TestResultSetNext() { try {//from w w w . j a va2 s . c om Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.first()); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.next()); Assert.assertEquals("yet", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.next()); Assert.assertEquals("would", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.next()); Assert.assertEquals("world", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.next()); Assert.assertEquals("without", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.next()); Assert.assertEquals("with", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.next()); Assert.assertEquals("your", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.next()); Assert.assertEquals("young", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.next()); Assert.assertEquals("words", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.next()); Assert.assertEquals("word", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertFalse(BQScrollableResultSetFunctionTest.Result.next()); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } try { Assert.assertEquals("", BQScrollableResultSetFunctionTest.Result.getString(1)); } catch (SQLException e) { boolean ct = e.toString().contains("Cursor is not in a valid Position"); if (ct == true) { Assert.assertTrue(ct); } else { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } } }
From source file:BQJDBC.QueryResultTest.BQScrollableResultSetFunctionTest.java
@Test public void TestResultIndexOutofBound() { try {//from w w w.j a v a2 s.com this.logger.debug(BQScrollableResultSetFunctionTest.Result.getBoolean(99)); } catch (SQLException e) { Assert.assertTrue(true); this.logger.error("SQLexception" + e.toString()); } }
From source file:BQJDBC.QueryResultTest.BQScrollableResultSetFunctionTest.java
@Test public void TestResultSetRelative() { try {//from w w w.ja va 2 s . c om Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(1)); Assert.assertEquals("you", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.relative(1)); Assert.assertEquals("yet", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.relative(2)); Assert.assertEquals("world", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.relative(5)); Assert.assertEquals("words", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.relative(-5)); Assert.assertEquals("world", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.relative(-2)); Assert.assertEquals("yet", BQScrollableResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.relative(-1)); Assert.assertEquals("you", BQScrollableResultSetFunctionTest.Result.getString(1)); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } try { Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.first()); Assert.assertFalse(BQScrollableResultSetFunctionTest.Result.relative(-1)); Assert.assertEquals("", BQScrollableResultSetFunctionTest.Result.getString(1)); } catch (SQLException e) { boolean ct = e.toString().contains("Cursor is not in a valid Position"); if (ct == true) { Assert.assertTrue(ct); } else { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } } try { Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.last()); Assert.assertFalse(BQScrollableResultSetFunctionTest.Result.relative(1)); Assert.assertEquals("", BQScrollableResultSetFunctionTest.Result.getString(1)); } catch (SQLException e) { boolean ct = e.toString().contains("Cursor is not in a valid Position"); if (ct == true) { Assert.assertTrue(ct); } else { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } } }
From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java
public void QueryLoad() { final String sql = "SELECT TOP(word,10) AS word, COUNT(*) as count FROM publicdata:samples.shakespeare"; final String description = "The top 10 word from shakespeare #TOP #COUNT"; String[][] expectation = new String[][] { { "you", "yet", "would", "world", "without", "with", "your", "young", "words", "word" }, { "42", "42", "42", "42", "42", "42", "41", "41", "41", "41" } }; /** somehow the result changed with time { "you", "yet", "would", "world", "without", "with", "will", "why", "whose", "whom" },/*from w ww.j a va2 s . c o m*/ { "42", "42", "42", "42", "42", "42", "42", "42", "42", "42" } }; */ this.logger.info("Test number: 01"); this.logger.info("Running query:" + sql); try { Statement stmt = BQResultSetFunctionTest.con.createStatement(); stmt.setQueryTimeout(500); BQResultSetFunctionTest.Result = stmt.executeQuery(sql); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } Assert.assertNotNull(BQResultSetFunctionTest.Result); this.logger.debug(description); this.printer(expectation); try { Assert.assertTrue("Comparing failed in the String[][] array", this.comparer(expectation, BQSupportMethods.GetQueryResult(BQResultSetFunctionTest.Result))); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail(e.toString()); } }
From source file:com.googlecode.flyway.core.migration.DbMigrator.java
/** * Applies this migration to the database. The migration state and the execution time are updated accordingly. * * @param migration The migration to apply. * @return The row that was added to the metadata table. * @throws MigrationException when the migration failed. *//* w w w . jav a2s .c o m*/ private MetaDataTableRow applyMigration(final Migration migration) throws MigrationException { MetaDataTableRow metaDataTableRow = new MetaDataTableRow(migration); LOG.info("Migrating to version " + migration.getVersion()); StopWatch stopWatch = new StopWatch(); stopWatch.start(); MigrationState state; try { final JdbcTemplate jdbcTemplate = new JdbcTemplate(connectionForMigrations) { @Override protected void setNull(PreparedStatement preparedStatement, int parameterIndex) throws SQLException { //No implementation needed } }; new TransactionTemplate(connectionForMigrations).execute(new TransactionCallback<Void>() { public Void doInTransaction() { try { migration.migrate(jdbcTemplate, dbSupport); } catch (SQLException e) { throw new FlywayException("Migration failed!", e); } return null; } }); LOG.debug("Successfully completed and committed DB migration to version " + migration.getVersion().toString()); state = MigrationState.SUCCESS; } catch (Exception e) { LOG.error(e.toString()); @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" }) Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause != null) { LOG.error("Caused by " + rootCause.toString()); } state = MigrationState.FAILED; } stopWatch.stop(); int executionTime = (int) stopWatch.getTotalTimeMillis(); if (MigrationState.FAILED.equals(state) && dbSupport.supportsDdlTransactions()) { throw new MigrationException(migration.getVersion(), true); } LOG.debug(String.format("Finished migrating to version %s (execution time %s)", migration.getVersion(), TimeFormat.format(executionTime))); metaDataTableRow.update(executionTime, state); metaDataTable.insert(metaDataTableRow); LOG.debug("MetaData table successfully updated to reflect changes"); return metaDataTableRow; }