h31ix

Untitled

Jun 3rd, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.logging.Level;
  3. import java.util.logging.Logger;
  4.  
  5. public class Database
  6. {
  7. Connection connection = null;
  8. Statement statement = null;
  9.  
  10. public Database(String file)
  11. {
  12. try
  13. {
  14. Class.forName("org.sqlite.JDBC");
  15. connection = DriverManager.getConnection("jdbc:sqlite:"+file);
  16. statement = connection.createStatement();
  17. }
  18. catch (ClassNotFoundException | SQLException e)
  19. {
  20. e.printStackTrace();
  21. }
  22. }
  23.  
  24. public ResultSet query(String query)
  25. {
  26. ResultSet rs = null;
  27. try
  28. {
  29. rs = statement.executeQuery(query);
  30. }
  31. catch (SQLException ex)
  32. {
  33. Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
  34. }
  35. return rs;
  36. }
  37.  
  38. public void execute(String query)
  39. {
  40. try
  41. {
  42. statement.executeUpdate(query);
  43. }
  44. catch (SQLException ex)
  45. {
  46. Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment