Guest User

Untitled

a guest
Mar 11th, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. package com.power.Economy;
  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. DriverManager.registerDriver(new org.sqlite.JDBC());
  21. this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.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. DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  31. this.connection = DriverManager.getConnection(urlconn);
  32. this.stmt = this.connection.createStatement();
  33. } catch (Exception e) {
  34. e.printStackTrace();
  35. }
  36. }
  37.  
  38. public Database(String host, String database, String user, String pass) {
  39. this("jdbc:mysql://" + host + "/" + database + "?" + "user=" + user + "&password=" + pass);
  40. }
  41.  
  42. public Connection getConnection() {
  43. return this.connection;
  44. }
  45.  
  46. public void update(String sql){
  47. try {
  48. this.stmt.executeUpdate(sql);
  49. } catch (Exception e) {
  50. e.printStackTrace();
  51. System.out.println("Erro ao Executar SQL");
  52. }
  53. }
  54.  
  55. public void update(PreparedStatement sql){
  56. try {
  57. sql.executeUpdate();
  58. } catch (Exception e) {
  59. e.printStackTrace();
  60. System.out.println("Erro ao Executar SQL");
  61. }
  62. }
  63.  
  64. public PreparedStatement prepareStatement(String sql){
  65. try {
  66. return this.connection.prepareStatement(sql);
  67. } catch (SQLException e) {
  68. System.out.print("[MsSQLConnection] SQLException: " + e.getCause());
  69. }
  70. return null;
  71. }
  72.  
  73. }
Add Comment
Please, Sign In to add comment