Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. package astatine.login.database;
  2.  
  3. import java.io.File;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9.  
  10. public class Database {
  11.  
  12.  
  13. private Connection connection;
  14. private File file;
  15. private Statement stmt;
  16.  
  17. public Database(File f) {
  18. this.file = f;
  19. try {
  20. Class.forName("org.sqlite.JDBC");
  21. this.connection = DriverManager.getConnection("jdbc:sqlite:" + file);
  22. this.stmt = this.connection.createStatement();
  23. } catch (Exception e) {
  24. e.printStackTrace();
  25. }
  26. }
  27.  
  28. private Database(String urlconn) {
  29. try {
  30. this.connection = DriverManager.getConnection(urlconn);
  31. this.stmt = this.connection.createStatement();
  32. } catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. }
  36.  
  37. public Database(String host, String database, String pass) {
  38. this("jdbc:mysql://" + host + "/" + database + "?" + "user=astatibr2@177.101.144.170&password=" + pass);
  39. }
  40.  
  41. public Connection getConnection() {
  42. return this.connection;
  43. }
  44.  
  45. public void update(String sql){
  46. try {
  47. this.stmt.executeUpdate(sql);
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. System.out.println("Erro ao Executar SQL");
  51. }
  52. }
  53.  
  54. public void update(PreparedStatement sql){
  55. try {
  56. sql.executeUpdate();
  57. } catch (Exception e) {
  58. e.printStackTrace();
  59. System.out.println("Erro ao Executar SQL");
  60. }
  61. }
  62.  
  63. public PreparedStatement prepareStatement(String sql){
  64. try {
  65. return this.connection.prepareStatement(sql);
  66. } catch (SQLException e) {
  67. System.out.print("SQLException: " + e.getCause());
  68. }
  69. return null;
  70. }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement