Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 KB | None | 0 0
  1. public static void viewTable(Connection con, String CPFent, String dbName) throws SQLException {
  2.     //nao sei exatamente como funcionara o resultado da pesquisa, mas eh coisa simples de corrigir (colocando como retorno ou colocando no parametro)
  3.     int salario;
  4.     String CPF_supervisionador;
  5.     String CPF_p;
  6.     String nome;
  7.     char genero;
  8.     String c;
  9.     String CEP;
  10.     String pais;
  11.     String rua;
  12.     String estado;
  13.     String bairro;
  14.     String complemento;
  15.     int numero;
  16.  
  17.     Statement stmt = null;
  18.     String query1 = "SELECT CPF_p, CPF_supervisionador, salario FROM " + dbName + ".Funcionario WHERE CPF_p = \"" + CPFent + "\"";
  19.     try {
  20.         stmt = con.createStatement();
  21.         ResultSet rs = stmt.executeQuery(query1);
  22.         while(rs.next()){
  23.             CPF_p = rs.getString("CPF_p");
  24.             CPF_supervisionador = rs.getString("CPF_supervisionador");
  25.             salario = rs.getInt("salario");
  26.         }
  27.     } catch (SQLException e ) {
  28.         JDBCTutorialUtilities.printSQLException(e);
  29.     } finally {
  30.         if (stmt != null) { stmt.close(); }
  31.     }
  32.  
  33.     stmt = null;
  34.     String query2 = "SELECT nome, genero, data_de_nascimento_inauguracao, CEP FROM " + dbName + ".Pessoa WHERE CPF_CNPJ = \"" + CPF_p + "\"";
  35.     try {
  36.         stmt = con.createStatement();
  37.         ResultSet rs = stmt.executeQuery(query2);
  38.         while(rs.next()){
  39.             nome = rs.getString("nome");
  40.             genero = rs.getChar("genero");
  41.             data_de_nascimento_inauguracao = rs.getString("data_de_nascimento_inauguracao");
  42.             CEP = rs.getString("CEP");
  43.         }
  44.     }
  45.     } catch (SQLException e ) {
  46.         JDBCTutorialUtilities.printSQLException(e);
  47.     } finally {
  48.         if (stmt != null) { stmt.close(); }
  49.     }
  50.  
  51.     stmt = null;
  52.     String query3 = "SELECT pais, estado, bairro, rua, complemento, numero FROM " + dbName + ".Endereco  WHERE CEP = \"" + CEP + "\"";
  53.     try {
  54.         stmt = con.createStatement();
  55.         ResultSet rs = stmt.executeQuery(query3);
  56.         while(rs.next()){
  57.             pais = rs.getString("pais");
  58.             estado = rs.getString("estado");
  59.             bairro = rs.getString("bairro");
  60.             rua = rs.getString("rua");
  61.             complemento = rs.getString("complemento");
  62.             numero = rs.getInt("numero");
  63.         }
  64.     } catch (SQLException e ) {
  65.         JDBCTutorialUtilities.printSQLException(e);
  66.     } finally {
  67.         if (stmt != null) { stmt.close(); }
  68.     }
  69.    
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement