Friday, August 28, 2009

Creating a war/ jar using Eclipse

Three steps to create a war/ jar using Eclipse:







Cheers,
-Ibu

Take care while evaluating the number of tokens in a STRINGTOKENIZER

A small tip while using StringTokenizer which may prove useful at times ;)

If I write :

StringTokenizer st = new StringTokenizer(to, ";");
int i=0;
while(st.hasMoreTokens()){
i++;
}

The above code will run into endless loop. Add st.nextToken(); to evaluate the value of i (number of tokens) in the string "to".

StringTokenizer st = new StringTokenizer(to, ";");
int i=0;
while(st.hasMoreTokens()){
st.nextToken();
i++;
}

Cheers,
-Ibu

Saturday, May 2, 2009

Establishing a connection with ORACLE EXPRESS(XP) in Java:

Assuming the Oracle Express Server is installed on a remote machine and you want your web application to connect to it.

The Oracle express client does not creates a tnsnames.ora on the client machine. This means, the oracle client folder does not contain the /ADMIN/NETWORK folder structure at all. So, create a new DNS giving username, pwd and check whether the connection is successful. If the connection is successful then with the following steps in your Java code.

Problem:
If the exception you are getting is similar to the one I got, then go for the checklist mentioned below:
  • Exception in thread "main" java.sql.SQLException: ORA-01034: ORACLE not available.
ORA-27101: shared memory realm does not exist
  • Exception in thread "main" java.sql.SQLException: Io exception: The Network Adapter could not establish the connection.
Resolution/ Checklist:
1. Check whether you are actually connected to the database. Try creating a DSN on client machine and checkwhether the connection is successful.
2. Set the Username and Password correctly.
3. Check for the URL in connection string, check for the machine name, IP and SID you mentioned in the setURL();

SID: By default it is XE,
URL:ocpds.setURL("jdbc:oracle:thin:@192.168.91.210:1521:XE");

Sample Code:
private void init()throws SQLException {
try {
OracleConnectionPoolDataSource ocpds = new OracleConnectionPoolDataSource();
java.util.Properties p = new java.util.Properties();
p.setProperty("oracle.jdbc.V8Compatible", "true");
ocpds.setConnectionProperties(p);
ocpds.setURL("jdbc:oracle:thin:@192.168.91.210:1521:XE");
ocpds.setUser("scott");
ocpds.setPassword("manager");
pool = ocpds.getPooledConnection();
}catch(SQLException ex){
ex.printStackTrace();
throw ex;
}
}

Cheers,
-Ibu

Saturday, March 28, 2009

How to configure multiple ApplicationResource.properties properties in Struts application

Considering you have multiple modules in your web application, you would obviously want to separate the resource bundles for each of them.

Steps:
1. Create separate resource bundles for each modules. Name them accordingly as per conventions and place them in the classpath folder.

2. Add following in the Struts-Config.xml file:
message-resources key="applicationResource_1" parameter="com/package/ApplicationResource"/>

3. Now, in a jsp to view the labels and message, you can sue the following tag:
< bundle="applicationResource_1" key="label.1">

Cheers,
-Ibu