Guest User

Untitled

a guest
Jul 11th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. package json.data;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10. import javax.sql.rowset.CachedRowSet;
  11.  
  12. public class DbOperations {
  13.  
  14. private Connection conn;
  15. private final String url;
  16. private final String dbName;
  17. private final String driver;
  18. private final String userName;
  19. private final String password;
  20. Statement stmt;
  21.  
  22. public DbOperations() {
  23.  
  24. conn = null;
  25. url = "jdbc:mysql://localhost:3306/";
  26. dbName = "vt";
  27. driver = "com.mysql.jdbc.Driver";
  28. userName = "root";
  29. password = "";
  30. stmt = null;
  31. }
  32.  
  33. public Connection getConnection() {
  34. return conn;
  35. }
  36.  
  37. public Statement openConnection() throws Exception {
  38. Class.forName(driver).newInstance();
  39. conn = DriverManager.getConnection(url + dbName, userName, password);
  40. return conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
  41.  
  42. }
  43.  
  44. public void closeConnection() throws Exception {
  45. conn.close();
  46. }
  47.  
  48.  
  49.  
  50. public CachedRowSet createStatement() {
  51. Statement st1;
  52. CachedRowSet resWanted = null;
  53.  
  54. try {
  55. st1 = conn.createStatement();
  56. resWanted = new com.sun.rowset.CachedRowSetImpl();
  57. } catch (SQLException ex) {
  58. Logger.getLogger(DbOperations.class.getName()).log(Level.SEVERE, null, ex);
  59. }
  60.  
  61. return resWanted;
  62. }
  63.  
  64. }
Add Comment
Please, Sign In to add comment