File tree Expand file tree Collapse file tree
src/main/java/dev/noah/perplayerkit/storage/sql Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424
2525public class SQLite implements SQLDatabase {
2626
27-
2827 private final String databasePath ;
2928 private Connection connection ;
3029
@@ -33,7 +32,11 @@ public SQLite(String databasePath) {
3332 }
3433
3534 public boolean isConnected () {
36- return (connection != null );
35+ try {
36+ return connection != null && !connection .isClosed () && connection .isValid (1 );
37+ } catch (SQLException e ) {
38+ return false ;
39+ }
3740 }
3841
3942 public void connect () throws ClassNotFoundException , SQLException {
@@ -43,17 +46,20 @@ public void connect() throws ClassNotFoundException, SQLException {
4346 }
4447 }
4548
46- public void disconnect () {
47- if (isConnected ()) {
48- try {
49- connection .close ();
50- } catch (SQLException e ) {
51- e .printStackTrace ();
52- }
49+ public void disconnect () throws SQLException {
50+ if (connection != null && !connection .isClosed ()) {
51+ connection .close ();
5352 }
5453 }
5554
56- public Connection getConnection () {
55+ public Connection getConnection () throws SQLException {
56+ if (!isConnected ()) {
57+ try {
58+ connect ();
59+ } catch (ClassNotFoundException e ) {
60+ throw new SQLException ("Failed to load SQLite driver" , e );
61+ }
62+ }
5763 return connection ;
5864 }
5965}
You can’t perform that action at this time.
0 commit comments