Advertisement
Guest User

Untitled

a guest
May 21st, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 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.  
  28.  
  29. private void closeConnection() throws SQLException{
  30. connection.close();
  31. }
  32.  
  33. void createLogin(){
  34. try{
  35. final Statement statement = connection.createStatement();
  36. statement.executeUpdate("SELECT imie, nazwisko FROM Studenci;");
  37. }catch (SQLException e){
  38. e.printStackTrace();
  39. }
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement