Monday, May 20, 2013

Java - Read excel file with blank cells

If you use normal cellIterator to iterate through excel cells it will skip blank cells. If you need to read blank cells as well you can use below method -

Tuesday, April 23, 2013

The Persuasion of Discussions on Internet Marketing


There are remarkable ideas that you can come across in various internet marketing forums. In whatever kind of forum you join, it is certain that you can have contact with plenty of information that can be useful to start your business. Novice and skilled people in the business usually join in discussions on online marketing with the aim of being taught something new by trading experiences and ideas that they have previously undergone in marketing.


The subject matter of these forums are discussions about SEO, making money, affiliate programs inclusive of others, advertising, search engines and social networks, and all that. The topics in the discussions are for any members who are in the online business and those intending to involve in internet marketing and make them feel part of a important community.

Previous to being part of any internet marketing debates, it will better if you seek out a forum that will be meeting your goals. The platform you choose must be definite to the business you are in to make certain that you maximize the resources. If you are probing through the possible forums, you can also check their FAQs and policies on the online marketing forum. This will assure that you will not breach and be obedient to their group and absolutely disbarred from their site.

Tuesday, April 2, 2013

Celebrities Team Up to Promote Coding



What do Microsoft inventor Bill Gates and music star Will.i.am have in common? They are just two famous people who have teamed up to create a YouTube video that promotes the idea that coding, an activity associated with computer programming, is cool and deserves attention.

Stoking the Desire to Learn

The video is focused on the idea that although many schools don't teach coding as part of regular coursework, students could aim to learn more through extracurricular activities, thus acquiring skills that could contribute to a brighter future. Coding is versatile, because it can be written in several programming languages such as Java and C++, among many others.

Technological opportunities are expanding at a rapid rate and many community colleges offer night classes in coding that cater to busy lifestyles. This means that both a Lancaster workers compensation lawyer and a chef who lives in Chicago are equally able to learn coding after their day job is done, provided the motivation is there. However, the YouTube video focuses more on the belief that coding should be taught in schools, while students are still young. It even calls the skill a “superpower.”

Ignore the Intimidation

The video addresses the common perception that coding is overly complicated. It also points out that as long as people are determined to learn, nothing can stop them.

In the video, NBA star Chris Bosh admits that while he was growing up, people made fun of him because of his interest in technology and coding. However, he was not deterred, and he continued studying the subjects to satisfy his hunger for knowledge. This promotes the idea that if a person feels that they’re not cut out to be a coder, or is getting negative feedback from a friend, that’s not a reason to stop learning something new.

Thursday, March 21, 2013

Hibernate : To handle special characters in HQL


In this article we will see to handle special characters in HQL similar to PreparedStatement in JDBC. It can also used for additional security purpose like to avoid SQL Injection.

For example, I have a below function in my BookDAO class to get detail of a particular book. It accepts bookTitle as a parameter and returns list of books. Here assume bookTitle can contain special characters.

public List findBook(String bookTitle) {
try {
String queryString = "from BsBooks where bookTitle = :bookTitle";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter("bookTitle", bookTitle);
return queryObject.list();
} catch (RuntimeException re) {
throw re;
}
}

Note - the method setParameter(), it is used to set the value for bookTitle, which can contain special characters.

queryObject.setParameter("bookTitle", bookTitle);

The above method will give following error if you try to use it like - queryObject.setParameter(0, bookTitle);

Exception in thread "main" java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!
at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterDescriptor(ParameterMetadata.java:79)
at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterExpectedType(ParameterMetadata.java:85)
at org.hibernate.impl.AbstractQueryImpl.determineType(AbstractQueryImpl.java:421)
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:393)


To avoid it you can use it as a '?' placeholder. When you execute the query, you would need to supply the value for it, which would replace the '?' in the query in below function.

public List findBook(String bookTitle) {
try {
String queryString = "from BsBooks where bookTitle = ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, bookTitle);
return queryObject.list();
} catch (RuntimeException re) {
throw re;
}
}


Below are the variations of the method setParameter, to know please see the API.

setParameter(int position, Object val) - Bind a value to a JDBC-style query parameter.

setParameter(int position, Object val, Type type) - Bind a value to a JDBC-style query parameter.

setParameter(String name, Object val) - Bind a value to a named query parameter.

setParameter(String name, Object val, Type type) - Bind a value to a named query parameter.

setParameterList(String name, Collection vals)  - Bind multiple values to a named query parameter.

setParameterList(String name, Collection vals, Type type) - Bind multiple values to a named query parameter.

setParameterList(String name, Object[] vals) - Bind multiple values to a named query parameter.

setParameterList(String name, Object[] vals, Type type) - Bind multiple values to a named query parameter.

setParameters(Object[] values, Type[] types) - Bind values and types to positional parameters.

Java : Function to return type of Object

Below is the java program which shows how to detect type of object in an ArrayList containing different types of Object.


Output :

Mike String
999 Integer
99.0 Double
Thu Mar 21 17:31:29 IST 2013 Date
true Boolean
java.lang.Object@3e25a5 String
null null