Guest User

ManagerConnection

a guest
Dec 20th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. package best.ranked.sql;
  2.  
  3. import java.sql.*;
  4.  
  5. public class ManagerConnection {
  6. public static Connection connection;
  7. public static Statement stmt;
  8.  
  9. public ManagerConnection(String urlconn, String user, String password) {
  10. try {
  11. Class.forName("com.mysql.jdbc.Driver");
  12. connection = DriverManager.getConnection(urlconn, user, password);
  13. stmt = connection.createStatement();
  14. } catch (Exception e) {
  15. e.printStackTrace();
  16. }
  17. }
  18.  
  19. public ManagerConnection(String host, String database, String user, String pass) {
  20. this("jdbc:mysql://" + host + "/" + database, user, pass);
  21. }
  22.  
  23. public static Connection getConnection() {
  24. return connection;
  25. }
  26.  
  27. public static void update(String sql) {
  28. try {
  29. stmt.executeUpdate(sql);
  30. } catch (Exception e) {
  31. e.printStackTrace();
  32. System.out.println("Erro ao Executar SQL");
  33. }
  34. }
  35.  
  36. public static void update(PreparedStatement sql) {
  37. try {
  38. sql.executeUpdate();
  39. } catch (Exception e) {
  40. e.printStackTrace();
  41. System.out.println("Erro ao Executar SQL");
  42. }
  43. }
  44.  
  45. public PreparedStatement prepareStatement(String sql) {
  46. try {
  47. return connection.prepareStatement(sql);
  48. } catch (SQLException e) {
  49. System.out.print("SQLException: " + e.getCause());
  50. }
  51. return null;
  52. }
  53. }
Add Comment
Please, Sign In to add comment