Advertisement
Guest User

Untitled

a guest
Apr 10th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. private Connection connection;
  2.  
  3.     public void ucitajDriver() throws Exception {
  4.         try {
  5.             Class.forName("com.mysql.jdbc.Driver");
  6.         } catch (ClassNotFoundException ex) {
  7.             throw new Exception("Neuspesno ucitavanje drivera!", ex);
  8.         }
  9.     }
  10.  
  11.     public void otvoriKonekciju() throws Exception {
  12.         try {
  13.             connection = DriverManager.getConnection("jdbc:mysql://localhost/poslovnipartneri", "root", "");
  14.             connection.setAutoCommit(false);
  15.             // Zahteva eksplicitnu potvrdu transakcije
  16.         } catch (SQLException ex) {
  17.             throw new Exception("Neuspesno otvaranje konekcije!", ex);
  18.         }
  19.     }
  20.  
  21.     public void commitTransakcije() throws Exception {
  22.         try {
  23.             connection.commit();
  24.         } catch (SQLException ex) {
  25.             throw new Exception("Neuspesan commit transakcije!", ex);
  26.         }
  27.     }
  28.  
  29.     public void rollbackTransakcije() throws Exception {
  30.         try {
  31.             connection.rollback();
  32.         } catch (SQLException ex) {
  33.             throw new Exception("Neuspesan rollback transakcije!", ex);
  34.         }
  35.     }
  36.  
  37.     public void zatvoriKonekciju() throws Exception {
  38.         try {
  39.             connection.close();
  40.         } catch (SQLException ex) {
  41.             throw new Exception("Neuspesno zatvaranje konekcije!", ex);
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement