Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. public class BancoDeDados {
  2. public void conexao(){
  3. try {
  4. System.out.println("Conectando ao Banco de Dados..");
  5. Class.forName("com.mysql.jdbc.Driver");
  6. Connection conexao = DriverManager.getConnection("jdbc:mysql://localhost:3306/despesas?useSSL=true","root","local");
  7. Statement mysql = conexao.createStatement();
  8. System.out.println("Conectado. n");
  9. } catch (ClassNotFoundException | SQLException e) {
  10. System.out.println("Erro na Conexão");
  11. }
  12. }
  13.  
  14. public void addDespesa(String addDesp){
  15. String sqlInsert;
  16. sqlInsert = "insert into tipo_de_despesa(descricao) values ('"+addDesp+"')";
  17. mysql.execute(sqlInsert);
  18. }
  19.  
  20. }
  21.  
  22. public class BancoDeDados {
  23.  
  24. private Statement mysql;
  25.  
  26. public void conexao(){
  27. try {
  28. System.out.println("Conectando ao Banco de Dados..");
  29. Class.forName("com.mysql.jdbc.Driver");
  30. Connection conexao = DriverManager.getConnection("jdbc:mysql://localhost:3306/despesas?useSSL=true","root","local");
  31. this.mysql = conexao.createStatement();
  32. System.out.println("Conectado. n");
  33. } catch (ClassNotFoundException | SQLException e) {
  34. System.out.println("Erro na Conexão");
  35. }
  36. }
  37.  
  38. public void addDespesa(String addDesp){
  39. String sqlInsert;
  40. sqlInsert = "insert into tipo_de_despesa(descricao) values ('"+addDesp+"')";
  41. mysql.execute(sqlInsert);
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement