Thursday, May 29, 2008

How to insatll Java plugins in Firefox on Fedora

Case 1: If you do not have have JDK >1.5 installed then download the jre for Fedora/Redhat from here:
http://java.com/en/download/help/5000010500.xml#download
And installed jre as steps given at same page.

Let say jre has been installed at /usr/java/jre1.6.0/

Case 2: If Firefox is installed as RPM then run the command:
$ cd /usr/lib/firefox-x.x.x.x/plugins
$ ln -s /usr/java/jre1.6.0/plugin/i386/ns7/libjavaplugin_oji.so

Case 3: If you already have JDK >1.5 installed then cd to jdk location.
Lets say jdk is insatlled at:
/usr/local/jdk1.5.0_09/
$ cd /usr/lib/firefox-x.x.x.x/plugins
$ ln -s /usr/local/jdk1.5.0_09/jre/plugin/i386/ns7/libjavaplugin_oji.so


Case 4: If Firefax has been installed manually then cd to firefox
Lets say Firefox is at /usr/local/firefox
$ cd /usr/local/firefox/plugins
$ ln -s /usr/local/jdk1.5.0_09/jre/plugin/i386/ns7/libjavaplugin_oji.so

or
$ ln -s /usr/java/jre1.6.0/plugin/i386/ns7/libjavaplugin_oji.so

Restart the Firefox:)

Friday, May 23, 2008

Using Jasper reports with Postgres database

As Jasper reports has been written in Java we need JDK/JRE installed on machine.
Download jasper report from here (jasperreports-3.0.0-project.tar.gz)
http://sourceforge.net/project/showfiles.php?group_id=36382&package_id=28579

Open it at some convenient location lets say:
/usr/local
A folder will be created jasperreports-3.0.0

Here we are going to create reports from the Postgres sql so we need Java Postgres driver.
Download driver from here:
http://jdbc.postgresql.org/download.html
Select appropriate jar file, means if JDK is >1.4 <1.6 and Postgres >8.1 then
download the JDBC3 (postgresql-8.2-508.jdbc3.jar)
Place this file at /usr/local/jasperreports-3.0.0/lib folder.

There are many sample reports type availabe in the jasperreports-3.0.0/demo/samples
Let say we are interested in the Charts type of report (Bar, Pie and Line charts)

To connet to the postgres database open the ChartsApp.java file.
By defualt Jasper uses inbuilt HSQL db and below function does this:
private static Connection getConnection() throws ClassNotFoundException, SQLException
{
//Change these settings according to your local configuration
String driver = "org.hsqldb.jdbcDriver";
String connectString = "jdbc:hsqldb:hsql://localhost";
String user = "sa";
String password = "";


Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);
return conn;
}


Change it to something like this:
// for postgre sql db
private static Connection getConnection() throws ClassNotFoundException, SQLException
//Change these settings according to your local configuration

String driver = "org.postgresql.Driver";
String connectString = "jdbc:postgresql://localhost:5432/YOUR_PG_DB_NAME";
String user = "PG_USER_NAME";
String password = "PG_USER_PASSWORD";

Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);
return conn;
}


Now in any one of the jrxml file you can write your sql query depending upon the requirement.

Whats new in Ajuby 0.5