Advertisement
Guest User

Untitled

a guest
Sep 21st, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  2.             throws ServletException, IOException {
  3.         List<Funcionario> funcionarios = new ArrayList<Funcionario>();
  4.        
  5.         Connection connection = null;
  6.         ResultSet result = null;
  7.        
  8.         try {
  9.             Class.forName("org.apache.derby.jdbc.ClientDriver");
  10.             connection = DriverManager.getConnection("jdbc:derby://localhost:1527/Empresa", "mack", "mack");
  11.             Statement statement = connection.createStatement();
  12.             result = statement.executeQuery("SELECT F.ID_FUNCIONARIO, F.NOME, C.ID_CARGO, C.NOME CARGO \n"
  13.                     + "FROM EMPRESA.FUNCIONARIO F \n"
  14.                     + "INNER JOIN EMPRESA.CARGO C \n"
  15.                     + "ON F.ID_CARGO = C.ID_CARGO");
  16.             while(result.next()) {
  17.                 funcionarios.add(new Funcionario(result.getInt("ID_FUNCIONARIO"),
  18.                         result.getString("NOME"),
  19.                         new Cargo(result.getInt("ID_CARGO"),
  20.                         result.getString("CARGO"))));
  21.             }
  22.         } catch (ClassNotFoundException | SQLException ex) {
  23.             Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
  24.         } finally {
  25.             try {
  26.                 if (result != null && !result.isClosed()) {
  27.                     result.close();
  28.                 }
  29.                 if (connection != null && !connection.isClosed()) {
  30.                     connection.close();
  31.                 }
  32.             } catch (SQLException ex) {
  33.                 Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
  34.             }
  35.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement