Advertisement
Guest User

Untitled

a guest
May 21st, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. package dbConnection;
  2.  
  3. import org.sqlite.SQLiteConfig;
  4.  
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9.  
  10. public class dbConnection {
  11. private static final String URL = "jdbc:sqlite:test:db";
  12. private Connection connection = null;
  13.  
  14. private static final String USERNAME = "dbuser";
  15. private static final String PASSWORD = "dbpassword";
  16. private static final String CONN = "jdbc:sqlite:cookBook.sqlite";
  17.  
  18. public static Connection getConnection() throws SQLException{
  19. try{
  20. Class.forName("org.sqlite.JDBC");
  21. return DriverManager.getConnection(CONN);
  22. }catch(ClassNotFoundException e){
  23. e.printStackTrace();
  24. }
  25. return null;
  26. }
  27. /*private void openConnection() throws SQLException {
  28. if (connection == null || connection.isClosed()) {
  29. SQLiteConfig config = new SQLiteConfig();
  30. config.enforceForeignKeys(true);
  31. connection = DriverManager.getConnection(URL, config.toProperties());
  32. }
  33. }*/
  34.  
  35. private void closeConnection() throws SQLException{
  36. connection.close();
  37. }
  38.  
  39. void createLogin(){
  40. try{
  41. final Statement statement = connection.createStatement();
  42. statement.executeUpdate("CREATE TABLE IF NOT EXISTS users(user_id INTEGER, username VARCHAR2, password VARCHAR2, PRIMARY KEY (user_id))");
  43. }catch (SQLException e){
  44. e.printStackTrace();
  45. }
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement