Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lojadepc;
- import java.sql.Connection;
- import java.sql.Statement;
- import javax.swing.JOptionPane;
- public class Comprador {
- public String nome;
- public String endereco;
- public String telefone;
- Statement sentence = null;
- Connection conexao = null;
- public Comprador (String nome, String endereco, String telefone) {
- this.nome = nome;
- this.endereco = endereco;
- this.telefone = telefone;
- }
- public String getNome(){
- return nome;
- }
- public String getEndereco(){
- return endereco;
- }
- public String getTelefone(){
- return telefone;
- }
- public void cadastraTransacao(Connection con){
- conexao = con;
- try
- {
- String query;
- {
- {
- query = "INSERT INTO Transacao (nome, endereco, telefone) "
- + "VALUES('" + this.nome + "', '" + this.endereco + "', '" + this.telefone + "')";
- }
- }
- System.out.println(query);
- sentence = conexao.createStatement();
- sentence.executeUpdate(query);
- JOptionPane.showMessageDialog(null, "Compra cadrastada!");
- }
- catch(Exception e)
- {
- JOptionPane.showMessageDialog(null, "Falha no cadastro.");
- System.out.println("Erro: " + e.toString());
- }
- }
- }
- ---------------------------------------------------------------------------------------------------------------------------------
- package lojadepc;
- import java.sql.*;
- import javax.swing.JOptionPane;
- public class ConnectionDataBase
- {
- Connection conexao;
- Statement sentenca;
- public Connection connect()
- {
- String url = "jdbc:postgresql://localhost:5433/postgres";
- String usuario = "root";
- String senha = "";
- try
- {
- Class.forName("org.postgresql.Driver");
- conexao = DriverManager.getConnection(url, usuario, senha);
- JOptionPane.showMessageDialog(null, "Conexao realizada com sucesso!");
- sentenca = conexao.createStatement();
- sentenca.execute("SET search_path TO transacao;");
- }
- catch(ClassNotFoundException e)
- {
- JOptionPane.showMessageDialog(null, "Erro Classe:" + e.getMessage());
- }
- catch(SQLException e)
- {
- JOptionPane.showMessageDialog(null, "Erro SQL:" + e.getMessage());
- }
- return conexao;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement