Pages

Thursday, October 20, 2011

Detecting an undefined object in JavaScript


typeof allows the identifier to never been declared before
if (typeof obj == "undefined")
instead of
if(obj == null) // will throw an error due to never declared


Wednesday, August 31, 2011

How to stop caching with jQuery ($.get(), $.ajax() etc) and javascript



To make it unique for each passes, we can place in a random number behind the url as shown below
$.get('remoteUrl.do?'+Math.random()+, function(data){
	$('#msg'+id).html(data);
}, 'html');


Set cache:false 
$.ajax({
	url: 'remoteUrl.do',
	cache: false,
	success: function(data){
		$('#resultDiv').append(data);
	} }); 
$.ajaxSetup({
	cache: false
});
Disable caching using html meta tag:

org.hibernate.PropertyAccessException

nested exception is org.hibernate.PropertyAccessException: Exception occurred inside getter of Hibernate Object

Reason:
  • Nullable database column was mapped to a primitive type property
  • The Hibernate type is not castable to the property type (or vice-versa)

  • Wednesday, July 13, 2011

    Tomcat - JDBC driver unregisted when the web application stops

    SEVERE: A web application registered the JBDC driver [oracle.jdbc.driver.OracleDriver] but failed to unregister it when the web application was stoppe

    Solution:

    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