Operation not allowed after ResultSet closed

March 5, 2010 Leave a comment

Result sets are implicitly closed when the statement that created them are closed. Statements are implicitly closed when the connection that created them are closed.

So it is not advisable to return an ResultSet for the method.

public ResultSet executeDBQuery(){
// try block
//Establish Connection connection = DriverManager.getConnection(url, userName, password);
//Statement st = connection.createStatement();
//resultSet = st.executeQuery(dBQuery);
//ResultSet will not contain any details if the connection is closed.
//Close connection
//return resultSet
}

Alternative :
public ResultSet executeDBQuery(){
// try block
//Establish Connection connection = DriverManager.getConnection(url, userName, password);
//Statement st = connection.createStatement();
//resultSet = st.executeQuery(dBQuery);
//do not close the connection
//return resultSet
}

ResultSet rs = DB..executeDBQuery()
//Now Close the connection

-Ram

Categories: Uncategorized

Reading property file in java

February 26, 2010 Leave a comment

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DBProperties {

private static final Log log = LogFactory.getLog(DBProperties.class);
private static final String fileName = “database.properties”;
private static Properties properties;
private static DBProperties instance = null;

private DBProperties() {
properties = new Properties();
try {
InputStream is = getClass().getClassLoader().getResourceAsStream(fileName);
properties.load(is);
} catch (IOException ioe) {
log.error(“Exception occurred while reading the ” + fileName + “file. ” + ioe.getMessage());
}
}

public static DBProperties getInstance() {
log.info(“GetInstance method of DBProperties class”);
if (null == instance) {
instance = new DBProperties();
}
return instance;
}

public String getProperty(String propertyName) {
return properties.getProperty(propertyName);
}
}

Categories: Java

Difference between JPA and hibernate

February 25, 2010 Leave a comment

Java Persistence API (JPA) is a standardized API for persistence in Java.

Hibernate is an implementation of JPA, as well as OpenJPA is another JPA implementation. Each implementation has specific features to extend the JPA functionalities.

JPA is a spec and not an implementation, so if you choose JPA, you still have to pick an implementation. You can pick Hibernate, Toplink, and any other ORM that implements JPA.

-Ram

Categories: Uncategorized

‘xcopy’ is not recognized as an internal or external command

February 22, 2010 Leave a comment

System32 folder might be missing from the PATH environmental variable. Please place this folder in the system path variable.

My Computer -> properties -> advanced ->Environment Variable

Now open a new window and then execute the command.

-Ram

Categories: Uncategorized

Charts in JSF

February 9, 2010 Leave a comment
Categories: JSF

Difference between javac and JIT

February 5, 2010 Leave a comment

Java compiler compiles source files (.java) to bytecode files (.class). Sun gives a free java compiler which is invoked with the ‘javac’ command.

A java interpreter is usually referred to as the Java Virtual Machine (or JVM). It reads and executes the bytecodes in the .class files.¬† Sun also supplies a free version of the JVM which is invoked with the ‘java’ command.

Where we get confusing is when people talk about a Just-In-Time compiler (or JIT compiler). This is actually part of a JVM. Its purpose is to take the generic (i.e. cross-platform) bytecodes and compile them into more machine-specific instructions (allowing the program to run significantly faster). Even though it is referred to as a JIT ‘compiler’, it is part of the Virtual Machine.

Now, this is what every JVM is facing: should it further translate those byte codes (using that JIT compiler) or should it interpret (or execute) these things itself? JIT compilation is just what it says: just in time compilation. Facing the choice of interpreting those byte codes itself (being slow) or compiling it into real machine code (by activating the JIT compiler) first and then let the real processor do the job, so the real machine code could get executed (or interpreted) by the real CPU is quite a choice to make.

-Ram

Categories: Uncategorized

antiJARLocking attribute set to true in the context xml

February 4, 2010 Leave a comment

If the antiJARLocking attribute is set to true in the context xml, the files contained in the jars will get loaded in the work\_\loader folder of tomcat and if the antiJARLocking attribute is not set to true then the loader folder will not be cretaed in work\_\ folder and also¬† the files(properties …etc) will be referred from the appropriate jar only.

It is good not to set the antiJARLocking attribute to true in the production environment.

-Ram

Categories: Uncategorized Tags: