33import xyz .theprogramsrc .supercoreapi .SuperPlugin ;
44
55import java .io .File ;
6+ import java .io .IOException ;
67import java .sql .Connection ;
78import java .sql .DriverManager ;
9+ import java .sql .SQLException ;
810
911public abstract class SQLiteDataBase implements DataBase {
1012
@@ -13,7 +15,6 @@ public abstract class SQLiteDataBase implements DataBase {
1315
1416 public SQLiteDataBase (SuperPlugin <?> plugin ){
1517 this .plugin = plugin ;
16-
1718 this .createConnection ();
1819 }
1920
@@ -23,7 +24,7 @@ private void createConnection() {
2324 if (!file .exists ()) file .createNewFile ();
2425 Class .forName ("org.sqlite.JDBC" );
2526 this .connection = DriverManager .getConnection ("jdbc:sqlite:" + file .getPath ());
26- }catch (Exception ex ){
27+ }catch (SQLException | ClassNotFoundException | IOException ex ){
2728 this .plugin .log ("&cCannot create SQLite Connection:" );
2829 ex .printStackTrace ();
2930 }
@@ -47,7 +48,7 @@ public void closeConnection() {
4748 if (this .connection != null ){
4849 this .connection .close ();
4950 }
50- }catch (Exception ex ){
51+ }catch (SQLException ex ){
5152 this .plugin .log ("&cCannot close SQLite Connection:" );
5253 ex .printStackTrace ();
5354 }
@@ -59,21 +60,19 @@ public void closeConnection() {
5960 */
6061 @ Override
6162 public void connect (ConnectionCall call ) {
62- if (this .connection == null ){
63- try {
63+ try {
64+ if (this .connection == null ){
65+ this .createConnection ();
66+ }else if (this .connection .isClosed ()){
6467 this .createConnection ();
65- }catch (Exception ex ){
66- this .plugin .log ("&cCannot connect with SQLite DataBase:" );
67- ex .printStackTrace ();
6868 }
69+ }catch (SQLException e ){
70+ this .plugin .addError (e );
71+ this .plugin .log ("&cError while connecting to SQLite:" );
72+ e .printStackTrace ();
6973 }
7074
71- try {
72- call .onConnect (this .connection );
73- }catch (Exception ex ){
74- this .plugin .log ("&cCannot execute ConnectionCall:" );
75- ex .printStackTrace ();
76- }
75+ call .onConnect (this .connection );
7776 }
7877
7978 /**
0 commit comments