From ecea320d3d2d340c3744a3f4d6a1e95fe1628b22 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 11 Jan 2008 11:24:20 +0000 Subject: [PATCH] git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/sqlite-jdbc@1944 ae02f08e-27ec-0310-ae8c-8ba02fe2eafd --- .../xerial/db/sql/sqlite/SQLiteJDBCLoaderTest.java | 75 +++++++++++----------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/src/test/java/org/xerial/db/sql/sqlite/SQLiteJDBCLoaderTest.java b/src/test/java/org/xerial/db/sql/sqlite/SQLiteJDBCLoaderTest.java index 1b9d352..8b385f5 100644 --- a/src/test/java/org/xerial/db/sql/sqlite/SQLiteJDBCLoaderTest.java +++ b/src/test/java/org/xerial/db/sql/sqlite/SQLiteJDBCLoaderTest.java @@ -24,6 +24,8 @@ //-------------------------------------- package org.xerial.db.sql.sqlite; +import static org.junit.Assert.fail; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -51,47 +53,48 @@ public class SQLiteJDBCLoaderTest public void query() throws ClassNotFoundException { SQLiteJDBCLoader.initialize(); - - // load the sqlite-JDBC driver into the current class loader - Class.forName("org.sqlite.JDBC"); - - Connection connection = null; - try - { - // create a database connection - connection = DriverManager.getConnection("jdbc:sqlite::memory:"); - Statement statement = connection.createStatement(); - statement.setQueryTimeout(30); // set timeout to 30 sec. - statement.executeUpdate("create table person ( id integer, name string)"); - statement.executeUpdate("insert into person values(1, 'leo')"); - statement.executeUpdate("insert into person values(2, 'yui')"); - - ResultSet rs = statement.executeQuery("select * from person order by id"); - while(rs.next()) - { - // read the result set - int id = rs.getInt(1); - String name = rs.getString(2); - } - } - catch(SQLException e) - { - // if e.getMessage() is "out of memory", it probably means no - // database file is found - - } - finally - { + // load the sqlite-JDBC driver into the current class loader + Class.forName("org.sqlite.JDBC"); + + Connection connection = null; + try + { + // create a database connection + connection = DriverManager.getConnection("jdbc:sqlite::memory:"); + Statement statement = connection.createStatement(); + statement.setQueryTimeout(30); // set timeout to 30 sec. + + statement.executeUpdate("create table person ( id integer, name string)"); + statement.executeUpdate("insert into person values(1, 'leo')"); + statement.executeUpdate("insert into person values(2, 'yui')"); + + ResultSet rs = statement.executeQuery("select * from person order by id"); + while (rs.next()) + { + // read the result set + int id = rs.getInt(1); + String name = rs.getString(2); + } + } + catch (SQLException e) + { + // if e.getMessage() is "out of memory", it probably means no + // database file is found + fail(e.getMessage()); + } + finally + { try { - if(connection != null) - connection.close(); + if (connection != null) + connection.close(); } - catch(SQLException e) + catch (SQLException e) { // connection close failed. + fail(e.getMessage()); } - } - } + } + } } -- 2.11.0