Odczyt obrazu z bazy danych

0
GET
	@Path("request=getTile")
	@Produces({"image/*"})
	public BufferedImage getTileGET(@QueryParam("id_photo")String id_photo,
						  @QueryParam("x")String x, 
						  @QueryParam("y")String y, 
						  @QueryParam("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;
		}	

Czy ktoś mógłby pomoc ? Chce żeby serwer zwracał mi zdjęcie z bazy

0

Masz metodę z jednego z moich projektów, która wyciągała obraz z bazy i działała prawidłowo.

public Image pobierzObrazUzytkownika (int id_uzytkownika) throws SQLException, IOException{
		Polacz();
		Statement st = connectionObject.createStatement();
	
		ResultSet rs = st.executeQuery("select obraz from uzytkownik where id ='"+id_uzytkownika+"'");
		InputStream in = null ;
		while (rs.next()) 
		in = rs.getBinaryStream(1);
		st.close();
		if (in !=null)
		return ImageIO.read(in);
		return null;
		
	}

 

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