Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. package lojadepc;
  2. import java.sql.Connection;
  3. import java.sql.Statement;
  4. import javax.swing.JOptionPane;
  5.  
  6. public class Comprador {
  7.  
  8.  
  9. public String nome;
  10. public String endereco;
  11. public String telefone;
  12.  
  13. Statement sentence = null;
  14. Connection conexao = null;
  15.  
  16. public Comprador (String nome, String endereco, String telefone) {
  17. this.nome = nome;
  18. this.endereco = endereco;
  19. this.telefone = telefone;
  20. }
  21.  
  22. public String getNome(){
  23. return nome;
  24. }
  25.  
  26. public String getEndereco(){
  27. return endereco;
  28. }
  29.  
  30. public String getTelefone(){
  31. return telefone;
  32. }
  33.  
  34. public void cadastraTransacao(Connection con){
  35. conexao = con;
  36. try
  37. {
  38. String query;
  39.  
  40. {
  41. {
  42. query = "INSERT INTO Transacao (nome, endereco, telefone) "
  43. + "VALUES('" + this.nome + "', '" + this.endereco + "', '" + this.telefone + "')";
  44. }
  45. }
  46.  
  47.  
  48. System.out.println(query);
  49. sentence = conexao.createStatement();
  50. sentence.executeUpdate(query);
  51. JOptionPane.showMessageDialog(null, "Compra cadrastada!");
  52. }
  53. catch(Exception e)
  54. {
  55. JOptionPane.showMessageDialog(null, "Falha no cadastro.");
  56. System.out.println("Erro: " + e.toString());
  57. }
  58. }
  59.  
  60. }
  61.  
  62. ---------------------------------------------------------------------------------------------------------------------------------
  63.  
  64.  
  65. package lojadepc;
  66.  
  67. import java.sql.*;
  68. import javax.swing.JOptionPane;
  69.  
  70. public class ConnectionDataBase
  71. {
  72. Connection conexao;
  73. Statement sentenca;
  74.  
  75. public Connection connect()
  76. {
  77. String url = "jdbc:postgresql://localhost:5433/postgres";
  78. String usuario = "root";
  79. String senha = "";
  80.  
  81. try
  82. {
  83. Class.forName("org.postgresql.Driver");
  84. conexao = DriverManager.getConnection(url, usuario, senha);
  85. JOptionPane.showMessageDialog(null, "Conexao realizada com sucesso!");
  86. sentenca = conexao.createStatement();
  87. sentenca.execute("SET search_path TO transacao;");
  88. }
  89. catch(ClassNotFoundException e)
  90. {
  91. JOptionPane.showMessageDialog(null, "Erro Classe:" + e.getMessage());
  92. }
  93. catch(SQLException e)
  94. {
  95. JOptionPane.showMessageDialog(null, "Erro SQL:" + e.getMessage());
  96. }
  97. return conexao;
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement