Guest User

Untitled

a guest
Dec 23rd, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public class BancoDeDados {
  2.  
  3. private Connection connection;
  4.  
  5. /**
  6. * inicia o banco
  7. */
  8. public void iniciar() {
  9. try {
  10. Class.forName("org.hsqldb.jdbcDriver");
  11. String url = "jdbc:hsqldb:file:target/bancoDeTeste";
  12. String username = "sa";
  13. String password = "";
  14. connection = DriverManager.getConnection(url, username, password);
  15. } catch (Exception e) {
  16. e.printStackTrace();
  17. throw new RuntimeException(e);
  18. }
  19. }
  20.  
  21. /**
  22. * termina o banco de dados.
  23. */
  24. public void terminar() {
  25. try {
  26. connection.createStatement().execute("SHUTDOWN");
  27. } catch (Exception e) {
  28. throw new RuntimeException(e);
  29. }
  30. }
  31.  
  32. /**
  33. * Obtem a connection usada para o banco.
  34. *
  35. * @return
  36. */
  37. public Connection getConnection() {
  38. return connection;
  39. }
  40. }
Add Comment
Please, Sign In to add comment