Wednesday, October 27, 2010

Postgres configuration

classical paths

# vi /etc/postgresql/8.2/main/postgresql.conf
# vi /var/lib/pgsql/data/postgresql.conf
# vi /opt/Postgres/8.4/data/postgresql.conf


Enable Network:

listen_addresses = 'localhost' to listen_addresses = '*'

You must also have appropriate entries in pg_hba.conf for hosts and
authentication type. You could use something like:

#TYPE DATABASE USER ADDRESS METHOD
local all all password
host all all 127.0.0.1/32 password
host all all 192.168.1.0/24 password

Next line allow all ips
host all all 0.0.0.0/0 md5

Thursday, October 21, 2010

Postgres save images


CREATE TABLE images (name text, img bytea);



File file = new File("image.gif");
FileInputStream fis = new FileInputStream(file);
PreparedStatement ps = conn.prepareStatement("INSERT INTO images VALUES (?, ?)");
ps.setString(1, file.getName());
ps.setBinaryStream(2, fis, file.length());
ps.executeUpdate();
ps.close();
fis.close();


setBinaryStream(), transfers a set number of bytes from a stream.
setBytes(), use this method if the contents of the image was already in a byte[].

Retrieving image

PreparedStatement ps = conn.prepareStatement("SELECT img FROM images WHERE name=?");
ps.setString(1, "image.gif");
ResultSet rs = ps.executeQuery();
if(rs.next()) {
byte[] imgBytes = rs.getBytes(1);
}
rs.close();
}
ps.close();


You could have used a InputStream object instead.

Alternatively you could be storing a very large file and want to use the LargeObject API to store the file:


CREATE TABLE imagesLO (imgname text, imgOID OID);

To insert an image, you would use:



conn.setAutoCommit(false); // All LargeObject API calls must be within a transaction

LargeObjectManager lobj = ((org.postgresql.PGConnection)conn).getLargeObjectAPI();

//create a new large object
int oid = lobj.create(LargeObjectManager.READ | LargeObjectManager.WRITE);

//open the large object for write
LargeObject obj = lobj.open(oid, LargeObjectManager.WRITE);

// Now open the file
File file = new File("image.gif");
FileInputStream fis = new FileInputStream(file);

// copy the data from the file to the large object
byte buf[] = new byte[2048];
int s, tl = 0;
while ((s = fis.read(buf, 0, 2048)) > 0)
{
obj.write(buf, 0, s);
tl += s;
}

obj.close();

//Now insert the row into imagesLO
PreparedStatement ps = conn.prepareStatement("INSERT INTO imagesLO VALUES (?, ?)");
ps.setString(1, file.getName());
ps.setInt(2, oid);
ps.executeUpdate();
ps.close();
fis.close();

Retrieving the image from the Large Object:


conn.setAutoCommit(false);

// Get the Large Object Manager to perform operations with
LargeObjectManager lobj = ((org.postgresql.PGConnection)conn).getLargeObjectAPI();

PreparedStatement ps = con.prepareStatement("SELECT imgOID FROM imagesLO WHERE imgname=?");
ps.setString(1, "image.gif");
ResultSet rs = ps.executeQuery();
if (rs.next())
{
int oid = rs.getInt(1);//open the large object for reading
LargeObject obj = lobj.open(oid, LargeObjectManager.READ);

//read the data
byte buf[] = new byte[obj.size()];
obj.read(buf, 0, obj.size());
//do something with the data read here
obj.close();
}
rs.close();
}
ps.close();

JSP Pagination mySQL Postgres

Postgres
select * from ubigeos order by nombre limit 10 offset 0

mySql
select * from ubigeos order by nombre limit 0 , 10

References:
[1] http://www.easywayserver.com/blog/jsp-pagination/
[2] http://www.todoexpertos.com/categorias/tecnologia-e-internet/programacion/java/respuestas/889187/paginacion-con-jsp

dbf tools

Dbf Viewer 2000 v2.02
http://www.megaupload.com/?d=6R0N6G2W

Thursday, October 14, 2010

haar cascading

http://www-personal.umich.edu/~shameem/haarcascade_eye.html

http://note.sonots.com/SciSoftware/haartraining.html

tomcat & servlet resource

Tomcat::configuration of system properties from webapp

SystemPropertiesListener.java
import java.util.Enumeration;
import javax.servlet.*;

public class SystemPropertiesListener implements
javax.servlet.ServletContextListener {
private ServletContext context = null;

public void contextInitialized(ServletContextEvent event) {
context = event.getServletContext();
Enumeration params = context.getInitParameterNames();

while (params.hasMoreElements()) {
String param = (String) params.nextElement();
String value = context.getInitParameter(param);
if (param.startsWith("prefix.")) {
System.setProperty(param, value);
}
}
}

public void contextDestroyed(ServletContextEvent event) {
}
}

web.xml

<context-param>
<param-name>prefix.property</param-name>
<param-value>value</param-value>
<param-type>java.lang.String</param-type>
</context-param>

<listener>
<listener-class>servletUtils.SystemPropertiesHelper</listener-class>
</listener>


Resources
[1] http://stackoverflow.com/questions/372686/how-can-i-specify-system-properties-in-tomcat-configuration-on-startup

[2] http://stackoverflow.com/questions/558502/how-a-servlet-can-get-the-absolute-path-to-a-file-outside-of-the-servlet
[3] http://stackoverflow.com/questions/2194930/tomcat-how-can-i-place-parameters-in-web-xml-and-fetch-them-in-my-application

Wednesday, October 13, 2010

Jasper Report

Ejemplo básico(src)
http://chuwiki.chuidiang.org/index.php?title=Ejemplo_b%C3%A1sico_con_Jasper_Report

Resources
http://abeishbabu.blogspot.com/2009/06/printing-txt-file-directly-to-printer.html
http://www.thatsjava.com/java-core-apis/46844/
http://java.itags.org/java-core-apis/46844/
http://jasperetl.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=34840
http://forums.java.net/jive/message.jspa?messageID=227537
http://www.coderanch.com/t/62982/open-source/Jasper-Report-Text-Exporter
http://helptodeveloper.blogspot.com/2010/02/exporting-jasper-reports-with-save-as.html

Friday, October 08, 2010

Google banner by date

2010-10-08

Web Service tools for Social Networks

Engine for Java Web service
http://enunciate.codehaus.org/

Social Networks Api
hi5
http://api.hi5.com/
Facebook
http://developers.facebook.com/docs/reference/javascript/

Animation online

Sketch to animation [1] https://sketch.metademolab.com/ Animate avatar from audio recorded [1] https://new.express.adobe.com/tools/animate-f...