Pages

Tuesday, June 29, 2010

Glassfish v2( JDBC Connection Pool, JNDI)

Step 1:
Place database driver in glassfish lib dir. (e.g. lib/mysql-jdbc-5.1.11.jar) and restart server.

Step 2:
Login to Admin Console: http:\\localhost:4848\
Goto Resource > JDBC > Connection Pool
Provide Name, Select Database vendor and Select Resource Type

Step 3:
Enter DataSource class name (Database driver)
Change other settings as you want

Save and Ping
:) "Ping Succeed"

Connection Pool is ready

Thursday, May 27, 2010

Converter - Convert MS Word/Excel to PDF

Converts MS Word to PDF, image etc
Converts MS Excel Spreadsheet to PDF, image etc

Supported formats, MS Word, Excel, Powerpoint, Txt, Csv, Flash, ODT, RTF, PDF.. etc.

Here is the code:

long startTime1 = System.currentTimeMillis();

// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(SocketOpenOfficeConnection.DEFAULT_PORT);
connection.connect();
DocumentConverter converter1 = new OpenOfficeDocumentConverter(connection);


File inputFile = new File("C:\\Miral\\temp\\myDocument.doc"));
File outputFile = new File("C:\\Miral\\temp\\myPortDocument.pdf");
totalFileSize+=(inputFile.length()/1024*100000)/100000;
converter1.convert(inputFile, outputFile);

System.out.println("Total File Size(kb): "+totalFileSize);
long endTime1 = System.currentTimeMillis();
System.out.println("Conversion Time: "+(endTime1-startTime1));
// close the connection
connection.disconnect();

Tuesday, April 27, 2010

iBatis (MyBatis)

How to call stored procedure in iBatis?

You can execute stored procedure via SqlMap xml file.
See the folloing example:

<!-- To call stored procedure. -->
<procedure id="getItemInfo" resultClass="Items" parameterMap="getItemInfoCall">
{ call getEmp( #invoiceNo# ) }
</procedure>


<parameterMap id="getItemInfoCall" class="map">
<parameter property="invoiceNo" jdbcType="INT" javaType="java.lang.Integer" mode="IN"/>

</parameterMap>

<!-- Now call this method -->

Reader rd = Resources.getResourceAsReader("SqlMapConfig.xml");

SqlMapClient smclient = SqlMapClientBuilder.buildSqlMapClient(rd);

int invoiceNo = 1;

System.out.println("Getting item information from db");

Items itm = (Items)smclient .queryForObject ("Items.getItemInfo", invoiceNo);






- Steps to generate doa, mapping files and pojos using iBator


- iBatis and Oracle selectByExamplePaginatedList
Google
 

Java-Struts