public static void createTables ( Connection connection ) throws Exception { StringBuilder sB = new StringBuilder ( ) ; sB . append ( "CREATE TABLE " ) ; sB . append ( TABLE_LOG ) ; sB . append ( " (" ) ; sB . append ( COLUMN_ID ) ; sB . append ( " INTEGER PRIMARY KEY AUTOINCREMENT, " ) ; sB . append ( COLUMN_DATAORA ) . append ( " INTEGER NOT NULL, " ) ; sB . append ( COLUMN_LOGMSG ) . append ( " TEXT " ) ; sB . append ( ");" ) ; String CREATE_TABLE = sB . toString ( ) ; sB = new StringBuilder ( ) ; sB . append ( "CREATE INDEX " + TABLE_LOG + "_" + COLUMN_ID + " ON " ) ; sB . append ( TABLE_LOG ) ; sB . append ( " ( " ) ; sB . append ( COLUMN_ID ) ; sB . append ( " );" ) ; String CREATE_INDEX = sB . toString ( ) ; sB = new StringBuilder ( ) ; sB . append ( "CREATE INDEX " + TABLE_LOG + "_" + COLUMN_DATAORA + " ON " ) ; sB . append ( TABLE_LOG ) ; sB . append ( " ( " ) ; sB . append ( COLUMN_DATAORA ) ; sB . append ( " );" ) ; String CREATE_INDEX_DATE = sB . toString ( ) ; try ( Statement statement = connection . createStatement ( ) ) { statement . setQueryTimeout ( 30 ) ; // set timeout to 30 sec. statement . executeUpdate ( CREATE_TABLE ) ; statement . executeUpdate ( CREATE_INDEX ) ; statement . executeUpdate ( CREATE_INDEX_DATE ) ; } catch ( Exception e ) { throw new IOException ( e . getLocalizedMessage ( ) ) ; } }
Create the default log table .