tags:

views:

25

answers:

1

hi there,

i am using java sqlite (org.sqlite.JDBC) with this i am adding a new row of data to the table, one field is supposed to take up a big amount of base64 encoded data (like pdf) the type of this field is sql-TEXT. now, if i delete the row with "DELETE FROM table WHERE id='id'" the row gets deleted as expected, my sqlite browser confirms this. but the table was befor the deletion like 4KB big, after adding the row it was 12MB and after deleting it remains 12MB big. is there a kind of cleanup i have to do? in sqlite admin(http://sqliteadmin.orbmu2k.de/) there is a "Cleanup" button after pressing that everything is fine, which means the database shrinks to its size befor adding stuff (4KB). after asking google i realy cannot find such a sql command. it seems that only the index informations get deleted from my databasefile, not the content itself. this behavior is known from windows delete functions.

beside that, here is the java snippet i use:

public void deleteRowById(String table, int id){
    try {
        Connection connection = null;
        Class.forName("org.sqlite.JDBC");
        connection = DriverManager.getConnection("jdbc:sqlite:C:\\meinedb");

        //statement = connection.createStatement();
        String sql = "DELETE FROM "+table+" WHERE id='"+id+"'";
        PreparedStatement pstmt = connection.prepareStatement(sql);
        pstmt.executeUpdate();
        pstmt.close();
        connection.close();
    } catch (SQLException ex) {
        Logger.getLogger(FileSpinner.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex){

    }

}
+1  A: 

You can shrink a SQLite database with the VACUUM statement. Read the manual I link to for details.

Bill Karwin