Wednesday, May 07, 2008

Make your JAVA application as executable jar file.

1. get the class file for the source code. create package structure for the class file.
In our example i have created a java file with a package structure as com.oracle.samples.HELLOWORLD.java.
Source Code for HELLOWORLD.java file.

package com.oracle.samples;

public class HELLOWORLD
{
public HELLOWORLD()
{
System.out.println("Iam printing from the HELLOWORLD constructor");
}

public static void main(String[] args) {
HELLOWORLD h = new HELLOWORLD();
}

}


D:\jdevstudio10133\jdk\bin\jar cvf HELLOWORLD.jar com\oracle\samples\HELLOWORLD.class

2. Create an empty folder and name it as META-INF.

3. Create a txt file and open that file in an editor. add the following line to it. Once added that line then hit the enter to get an empty line.
The empty line is very important, otherwise your manifest addition will not work.

main-class: com.oracle.samples.HELLOWORLD

D:\jdevstudio10133\jdk\bin\jar umf manifest.txt HELLOWORLD.jar

4. Once you done with the above steps you are ready to run the executable jar file.

D:\jdevstudio10133\jdk\bin\java -jar HELLOWORLD.jar

Note: If you want to add some jar files for your application you need to follow the steps below.
Create a folder called "lib" drop the your jar files under the folder example: log4j-1.2.13.jar or ojdbc14.jar
In the manifest.txt file you have to add one more line to it, add the below line.
Class-Path: lib\ojdbc14.jar lib\log4j-1.2.13.jar
After entering the above in the manifest.txt file you have hit the enter to have a empty line. This is very important otherwise you will get exception.

If you want to add properties file, you have to follow the below steps.
You can add the properties file inside the jar file or you can keep outside the jar file.

Monday, May 05, 2008

ORA-01000: maximum open cursors exceeded

Assum that you are looping through your result set.

If you get the "ORA-01000: maximum open cursors exceeded" error in java class, please check the following.

1. You should be having only one statemens object using connection(either statement, prepared statement or callable statement) and only one connection.

2. To make only single object for statements you can use the following check point before creating a new statements. It could be for any statements.
The below example is for prepared statement.
if(oPreparedStatement == null)
{
oPreparedStatement = oConn.getPreparedStatement(sPersonIdentifierQuery);
}

3. In your finally block don't forget to close the connection, statements and make them null. By following thies way you can get rid of the "ORA-01000: maximum open cursors exceeded exception".

4.The use of prepared statement is to compile the sql query and use it asmany time as you want, no need to prepare the statement again and again.