Posts

Showing posts from February, 2012

Generate Jar file with eclipse Indigo

Create a Java Application and Source files and libraries to it. Right click on the project->Export->Jar File-Click on Next until you see JAR manifest specifications dialogue box. Select -Generate Manifest file Click on browse and select the Main file. Click on Finish

Key Points on HashMap

Key Points on HashMap HashMap works on the principal of Hashing. HashMap uses LinkedList for storage.Each Node stores key and value. HashMap is not synchronised. hashcode() method is applied on the key object to store the value. override hashCode equals when implementing a hasmap. When the size of the hashmap exceeds the threshold defined loadfactor,a new buket location is created with double the sizeand starts rehashing.

Download Commons Apache Digester 3.0 Example

The pdf file contains steps followed to parse a complex xml file using apache digester. Also explains how the digester works. The code in the pdf is Tested. Click on the link ---> Download Apache Digester 3.0 sample Else click on the Link below https://docs.google.com/open?id=1JEhPkDmE5S7OvPHbkxThWcOLxZthoIn5-SR3EJ5meW4UG46SguTccb0gUK0W

Spring JDBC Abstarction framework Hirerachy

Spring JDBC Abstarction framework Hirerachy Contains 4 main Packages: core datasource Object support i.e org.springframework.jdbc.core org.springframework.jdbc.datasource org.springframework.jdbc.object org.spring framework.jdbc.support.

Add Jars to Local Maven repository

The mvn install:install file  command can be used to add a  jar to the local repo. However you can use the .java class in my prev post to generate the install script just be changing the directory path. mvn install:install-file -Dfile=path-to-file -DgroupId=group-id -DartifactId=artifact-id -Dversion=version -Dpackaging=packaging--can begievn as .jar -DgeneratePom=true Here is the sample install scripts mvn install:install-file -Dfile=E:\AppWithNewJars\WebContent\WEB-INF\lib\commons-beanutils-1.8.3.jar -DgroupId=commons-beanutils -DartifactId=commons-beanutils-1.8.3 -Dversion=1.8.3 -Dpackaging=jar -DgeneratePom=true mvn install:install-file -Dfile=E:\AppWithNewJars\WebContent\WEB-INF\lib\commons-fileupload-1.2.2.jar -DgroupId=commons-fileupload -DartifactId=commons-fileupload-1.2.2 -Dversion=1.2.2 -Dpackaging=jar -DgeneratePom=true mvn install:install-file -Dfile=E:\AppWithNewJars\WebContent\WEB-INF\lib\commons-io-2.0.1.jar -DgroupId=commons-io -DartifactId=co

Generate Maven dependency to be added to POM file

Suppose you have lot of .jar files in your lib folder.Adding each of the jar entry into the POM.xml file is quite tedious. So I came up with the below java program which will generate the dependency tag. A user can just paste its output directly into the POM.xml The below utility also generates the mvn install scripts that can be used to-- add jars to the local maven repo. package com.prdc.spring3; import java.io.File; public class DependencyGenerator { private String pom; private String install; public static String generate_dependency_pom(String lib_location){ String pom = null; String files=null; File folder = new File(lib_location); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { files = listOfFiles[i].getName(); pom = "\n\t<dependency> \n

Apache Common's Digester Examples

Digester is a very usefull api for parsing -xml documents.It acts like wrapper around  sax and dom parser and is quite simple once the rules are defined. It was orginally developed to parse the struts.xml file. There are two ways for defining the rules for parsing: define rules in the java define rules in the xml file. Steps: Analyse the xml file Create Java Class Create an Object Digester class in CustomDigester Define rules in the Digester class Parse the xml file XML file dtd is avialable -in digester api-digester-rules.dtd To get short training and examples on apache digester.leave a Comment with your e-mail id--below.  Each example is unique and gives good insight into the digester package.   package com.anjana.service; import java.io.IOException; import org.apache.commons.digester.Digester; import org.apache.commons.digester.xmlrules.DigesterLoader; import org.xml.sax.SAXException; public class DigesterXMLJavaStudents { public static void m

get First 100 rows of the table in mysql

MySQL and PostgreSQL SQL would use LIMIT like so: SELECT column FROM table LIMIT 100

Connect to MySQL DataBase using DataSource without connection pool

Connect to Mysql-database using datasource import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; public class UserDAOTest { MysqlDataSource ds; public UserDAOTest() { ds=new MysqlDataSource(); ds.setDatabaseName("csajsp"); ds.setURL("jdbc:mysql://localhost:3306/csajsp"); ds.setPassword("prdc123"); ds.setUser("root"); ds.getConnection(); }