Pobieranie zdjęcia z bazy danych

0

Witam. Mam serwer JAX-RS, który ma za zadanie zwrócić mi z bazy danych zdjęcie (które jest zakodowane w bazie typ:bytea). W jaki sposób można łatwo odkodować zdjęcie podając w zapytaniu konkretne parametry i żeby serwer je zwrócił ?

@POST
    @Path("/tiles")
    public BufferedImage getTilePOST(@FormParam("id_photo")String id_photo,
                                      @FormParam("x")String x, 
                                      @FormParam("y")String y, 
                                      @FormParam("zoom")String zoom) throws SQLException, IOException  {
 
        BufferedImage BI = null;
        connection dbs = new connection();
        Statement statement = null;
        Connection con = dbs.getConnection();
        PreparedStatement ps = null;
 
        try {
            ps = con.prepareStatement("SELECT image from tiles where id_photo = '"+id_photo+"' "
                    + "and x ='"+x+"' and y ='"+y+"' and zoom = '"+zoom+"';");
 
            ResultSet rs = ps.executeQuery();
 
            while (rs.next()) {
                InputStream input = rs.getBinaryStream("image");
                BI=ImageIO.read(input);
                input.close();
            }
 
        } 
        catch (SQLException e )
        {
            e.printStackTrace();
            System.out.println("Zle dane");
        }
        finally {
            if (statement != null) {
                statement.close();
            }
 
            if (con != null) {
                con.close();
            }
        }
 
        return BI;
    }

Próbowałem coś takiego.

0

Ja tam bym nie trzymał grafiki w bazie danych, tylko w systemie plików, a w bazie co najwyżej nazwę pliku/identyfikator

1 użytkowników online, w tym zalogowanych: 0, gości: 1