Corrected major condition error and removed duplicated code.

The problem was : If the connection is closed, exceptions are generated.
If the connection is open, everything runs fine but there is no need for that condition.

Reversed the condition so that it is opened only if it hasn't been before.

Also massively lightened up the code since 75% of it was duplicated in both MySQL and SQLite class, thanks to Java abstraction. Put all of it in Database.