You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Miroslav F." <mi...@seznam.cz> on 2011/07/02 13:39:46 UTC

image from data

Hi folks,

I have images in database as BLOBs and retrieving it with JDBC (not good
code, just test at the moment)
with this (just snip of the code):

conn = Utils.makeConnection();//make connection with JDBC
try
{
	conn.setAutoCommit(false);
	st = conn.createStatement();
	rs = st.executeQuery("SELECT * FROM testdatabase.images");
	LargeObjectManager lobj = ((org.postgresql.PGConnection)
conn).getLargeObjectAPI();
	while(rs.next())
	{
		Long oid = rs.getLong(7);
		LargeObject obj = lobj.open(oid, LargeObjectManager.READ);
		byte buf[] = new byte[obj.size()];
		obj.read(buf, 0, obj.size());
		//-->now I have image data in buf[], how can I put them into
html?
		obj.close();
	}
	rs.close();
	st.close();
	conn.commit();
}
catch(SQLException e)
{
	e.printStackTrace();
}

How can I put this image data into html page? Save it as file onto file
system and then
insert in src atribute of img tag? Or something else? Example is welcome.

Thanks in advance,

Miro


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: image from data

Posted by "Miroslav F." <mi...@seznam.cz>.
Adam,

thanks for pointing me this, after reading doc and few examles it works for
me. I have found this source:
https://svn.apache.org/repos/test/wicket/releases/wicket-1.2.1/wicket-exampl
es/src/java/wicket/examples/captcha/JCaptcha.java
where is nice example of using DynamicImageResource

Miro

 

> -----Original Message-----
> From: Adam Gray [mailto:adam.j.gray@gmail.com] 
> Sent: Saturday, 02. July 2011 14:42
> To: users@wicket.apache.org
> Subject: Re: image from data
> 
> Perhaps check out DynamicImageResource?
> 
> On Sat, Jul 2, 2011 at 7:39 AM, Miroslav F. <mi...@seznam.cz> wrote:
> 
> > Hi folks,
> >
> > I have images in database as BLOBs and retrieving it with JDBC (not 
> > good code, just test at the moment) with this (just snip of 
> the code):
> >
> > conn = Utils.makeConnection();//make connection with JDBC try {
> >        conn.setAutoCommit(false);
> >        st = conn.createStatement();
> >        rs = st.executeQuery("SELECT * FROM testdatabase.images");
> >        LargeObjectManager lobj = ((org.postgresql.PGConnection) 
> > conn).getLargeObjectAPI();
> >        while(rs.next())
> >        {
> >                Long oid = rs.getLong(7);
> >                LargeObject obj = lobj.open(oid, 
> LargeObjectManager.READ);
> >                byte buf[] = new byte[obj.size()];
> >                obj.read(buf, 0, obj.size());
> >                //-->now I have image data in buf[], how can 
> I put them 
> > into html?
> >                obj.close();
> >        }
> >        rs.close();
> >        st.close();
> >        conn.commit();
> > }
> > catch(SQLException e)
> > {
> >        e.printStackTrace();
> > }
> >
> > How can I put this image data into html page? Save it as file onto 
> > file system and then insert in src atribute of img tag? Or 
> something 
> > else? Example is welcome.
> >
> > Thanks in advance,
> >
> > Miro
> >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: image from data

Posted by Adam Gray <ad...@gmail.com>.
Perhaps check out DynamicImageResource?

On Sat, Jul 2, 2011 at 7:39 AM, Miroslav F. <mi...@seznam.cz> wrote:

> Hi folks,
>
> I have images in database as BLOBs and retrieving it with JDBC (not good
> code, just test at the moment)
> with this (just snip of the code):
>
> conn = Utils.makeConnection();//make connection with JDBC
> try
> {
>        conn.setAutoCommit(false);
>        st = conn.createStatement();
>        rs = st.executeQuery("SELECT * FROM testdatabase.images");
>        LargeObjectManager lobj = ((org.postgresql.PGConnection)
> conn).getLargeObjectAPI();
>        while(rs.next())
>        {
>                Long oid = rs.getLong(7);
>                LargeObject obj = lobj.open(oid, LargeObjectManager.READ);
>                byte buf[] = new byte[obj.size()];
>                obj.read(buf, 0, obj.size());
>                //-->now I have image data in buf[], how can I put them into
> html?
>                obj.close();
>        }
>        rs.close();
>        st.close();
>        conn.commit();
> }
> catch(SQLException e)
> {
>        e.printStackTrace();
> }
>
> How can I put this image data into html page? Save it as file onto file
> system and then
> insert in src atribute of img tag? Or something else? Example is welcome.
>
> Thanks in advance,
>
> Miro
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>