Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- List<Funcionario> funcionarios = new ArrayList<Funcionario>();
- Connection connection = null;
- ResultSet result = null;
- try {
- Class.forName("org.apache.derby.jdbc.ClientDriver");
- connection = DriverManager.getConnection("jdbc:derby://localhost:1527/Empresa", "mack", "mack");
- Statement statement = connection.createStatement();
- result = statement.executeQuery("SELECT F.ID_FUNCIONARIO, F.NOME, C.ID_CARGO, C.NOME CARGO \n"
- + "FROM EMPRESA.FUNCIONARIO F \n"
- + "INNER JOIN EMPRESA.CARGO C \n"
- + "ON F.ID_CARGO = C.ID_CARGO");
- while(result.next()) {
- funcionarios.add(new Funcionario(result.getInt("ID_FUNCIONARIO"),
- result.getString("NOME"),
- new Cargo(result.getInt("ID_CARGO"),
- result.getString("CARGO"))));
- }
- } catch (ClassNotFoundException | SQLException ex) {
- Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- try {
- if (result != null && !result.isClosed()) {
- result.close();
- }
- if (connection != null && !connection.isClosed()) {
- connection.close();
- }
- } catch (SQLException ex) {
- Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement