Skip to content

Instantly share code, notes, and snippets.

@guenodz
Last active December 14, 2015 06:09
Show Gist options
  • Save guenodz/5040411 to your computer and use it in GitHub Desktop.
Save guenodz/5040411 to your computer and use it in GitHub Desktop.
A Java class for SQLite conection Helper.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionManager {
private static Connection connection;
// path to the database file
private static final String dbPath = "tips.db";
private ConnectionManager() {
try {
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:" + dbPath);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static Connection getInstance() {
if (connection == null)
new ConnectionManager();
return connection;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment