Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dbConnection;
- import org.sqlite.SQLiteConfig;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class dbConnection {
- private static final String URL = "jdbc:sqlite:test:db";
- private Connection connection = null;
- private static final String USERNAME = "dbuser";
- private static final String PASSWORD = "dbpassword";
- private static final String CONN = "jdbc:sqlite:cookBook.sqlite";
- public static Connection getConnection() throws SQLException{
- try{
- Class.forName("org.sqlite.JDBC");
- return DriverManager.getConnection(CONN);
- }catch(ClassNotFoundException e){
- e.printStackTrace();
- }
- return null;
- }
- /*private void openConnection() throws SQLException {
- if (connection == null || connection.isClosed()) {
- SQLiteConfig config = new SQLiteConfig();
- config.enforceForeignKeys(true);
- connection = DriverManager.getConnection(URL, config.toProperties());
- }
- }*/
- private void closeConnection() throws SQLException{
- connection.close();
- }
- void createLogin(){
- try{
- final Statement statement = connection.createStatement();
- statement.executeUpdate("CREATE TABLE IF NOT EXISTS users(user_id INTEGER, username VARCHAR2, password VARCHAR2, PRIMARY KEY (user_id))");
- }catch (SQLException e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement