Advertisement
Guest User

Untitled

a guest
May 13th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. package Clase;
  2.  
  3. import java.sql.*;
  4.  
  5. public class DatabaseOperations {
  6.  
  7. public static DatabaseOperations instance = null;
  8. public Connection con;
  9.  
  10. private DatabaseOperations() {
  11. String url = "jdbc:odbc:db1";
  12. String username = "root";
  13. String password = "root";
  14.  
  15. try {
  16. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  17.  
  18. } catch(java.lang.ClassNotFoundException e) {
  19. System.err.print("ClassNotFoundException: ");
  20. System.err.println(e.getMessage());
  21. }
  22.  
  23. try {
  24. this.con = DriverManager.getConnection(url, username, password);
  25. } catch(SQLException ex) {
  26. System.err.println("SQLException: " + ex.getMessage());
  27. }
  28. }
  29.  
  30. public static DatabaseOperations getInstance() {
  31. if(instance == null) {
  32. instance = new DatabaseOperations();
  33. }
  34. return instance;
  35. }
  36.  
  37. public ResultSet execute(String string)
  38. {
  39. DatabaseOperations db = DatabaseOperations.getInstance();
  40. ResultSet rs = null;
  41.  
  42. try {
  43. Statement stmt = db.con.createStatement();
  44. rs=stmt.executeQuery(string);
  45.  
  46. } catch (SQLException e) {
  47. // TODO Auto-generated catch block
  48. e.printStackTrace();
  49. System.out.println(e.getMessage());
  50. }
  51. return rs;
  52. }
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement