Advertisement
Guest User

Untitled

a guest
Apr 17th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. try {
  2. Connection conn = db.getConnection() ;
  3. StringBuilder sql = new StringBuilder() ;
  4. sql.append("VACUUM");
  5.  
  6. //PreparedStatement prep = conn.prepareStatement(sql.toString()) ;
  7. Statement stat = conn.createStatement() ;
  8. boolean rs = stat.execute(sql.toString()) ;
  9.  
  10. System.out.println("Executed vacuum " + rs ) ;
  11.  
  12. //Testing code--preparedstatement attempts
  13. //conn.setAutoCommit(false);
  14. //boolean rs = prep.execute() ;
  15. //conn.setAutoCommit(true);
  16.  
  17. } catch (Exception e) {
  18. //Edited back in after posting to StackOverflow
  19. System.out.println(
  20. ".SQLiteVacuum :: exception " +
  21. e.getMessage() + " " + e.getClass().getName() );
  22. e.printStackTrace() ;
  23. }
  24.  
  25. private final String dbJDBCdriverclassname = "org.sqlite.JDBC" ;
  26. private final String dbJDBCpreconnectionstring = "jdbc:sqlite:" ;
  27. // Setup the driver reference
  28. Class.forName(dbJDBCdriverclassname) ; //"org.sqlite.JDBC"
  29.  
  30. // Create the connection string
  31. String connstring = dbJDBCpreconnectionstring + this.getDBConnectionFullFileName() ;
  32.  
  33. // create the connection
  34. dbconnection =
  35. DriverManager.getConnection(connstring) ; // "jdbc:sqlite:test.db"
  36.  
  37. Statement stmt = null;
  38. ResultSet rs = null;
  39. try {
  40. Connection conn = DBConnection.getConnection();//something to get a connection
  41. stmt = conn.createStatement();
  42. stmt.executeUpdate("VACUUM");
  43. } catch (SQLException ex) {
  44. //Something if you like, or not you're the boss!
  45. } finally {
  46. DBConnection.closeResources(rs, stmt);//something to close all the resources
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement