FileDocCategorySizeDatePackage
SQLiteJDBCDriverTest.javaAPI DocAndroid 1.5 API4218Wed May 06 22:42:02 BST 2009android.core

SQLiteJDBCDriverTest

public class SQLiteJDBCDriverTest extends AbstractJDBCDriverTest
Minimal test for JDBC driver

Fields Summary
private File
dbFile
Constructors Summary
Methods Summary
protected java.lang.StringgetConnectionURL()

        return "jdbc:sqlite:/" + dbFile;
    
protected java.io.FilegetDbFile()

        return dbFile;
    
protected java.lang.StringgetJDBCDriverClassName()

        return "SQLite.JDBCDriver";
    
protected voidsetUp()

        super.setUp();
        dbFile = File.createTempFile("sqliteTestDB", null);
    
protected voidtearDown()

        if(dbFile != null) {
            dbFile.delete();
        }
        super.tearDown();
    
public voidtest_connection3()

        PreparedStatement prst = null;
        Statement st = null;
        Connection conn = null;
        try {
            Class.forName("SQLite.JDBCDriver").newInstance();
            if (dbFile.exists()) {
                dbFile.delete();
            }
            conn = DriverManager.getConnection("jdbc:sqlite:/"
                        + dbFile.getPath());
            assertNotNull(conn);

            // create table
            st = conn.createStatement();
            String sql = "CREATE TABLE zoo (ZID INTEGER NOT NULL, family VARCHAR (20) NOT NULL, name VARCHAR (20) NOT NULL, PRIMARY KEY(ZID) )";
            st.executeUpdate(sql);
            
            String update = "update zoo set family = ? where name = ?;";
            prst = conn.prepareStatement(update);
            prst.setString(1, "cat");
            prst.setString(2, "Yasha");
            // st = conn.createStatement();
            // st.execute("select * from zoo where family = 'cat'");
            // ResultSet rs = st.getResultSet();
            // assertEquals(0, getCount(rs));
            prst.executeUpdate();
            // st.execute("select * from zoo where family = 'cat'");
            // ResultSet rs1 = st.getResultSet();
            // assertEquals(1, getCount(rs1));
            try {
                prst = conn.prepareStatement("");
                prst.execute();
                fail("SQLException is not thrown");
            } catch (SQLException e) {
                // expected
            }
            
            try {
                conn.prepareStatement(null);
                fail("NPE is not thrown");
            } catch (Exception e) {
                // expected
            }
            try {
                st = conn.createStatement();
                st.execute("drop table if exists zoo");
                
            } catch (SQLException e) {
                fail("Couldn't drop table: " + e.getMessage());
            } finally {
                try {
                    st.close();
                    conn.close();
                } catch (SQLException ee) {
                }
            }
        } finally {
            try {
                if (prst != null) {
                    prst.close();
                }
                if (st != null) {
                    st.close();
                }
            } catch (SQLException ee) {
            }
        }