Sunday, December 5, 2010

DOS Script to detect Windows/OS Version

Simply save the following script in a .bat file and run, it will detect the OS version and will give you the results.


# detectOS.bat


@echo off

ver | find "2003" > nul

if %ERRORLEVEL% == 0 goto ver_2003

ver | find "XP" > nul

if %ERRORLEVEL% == 0 goto ver_xp

ver | find "2000" > nul

if %ERRORLEVEL% == 0 goto ver_2000

ver | find "NT" > nul

if %ERRORLEVEL% == 0 goto ver_nt

if not exist %SystemRoot%\system32\systeminfo.exe goto warnthenexit

systeminfo | find "OS Name" > %TEMP%\osname.txt

FOR /F "usebackq delims=: tokens=2" %%i IN (%TEMP%\osname.txt) DO set vers=%%i

echo %vers% | find "Windows 7" > nul

if %ERRORLEVEL% == 0 goto ver_7

echo %vers% | find "Windows Server 2008" > nul

if %ERRORLEVEL% == 0 goto ver_2008

echo %vers% | find "Windows Vista" > nul

if %ERRORLEVEL% == 0 goto ver_vista

goto warnthenexit


:Run Windows 7 specific commands here.

echo Windows 7

goto exit


:Run Windows Server 2008 specific commands here.

echo Windows Server 2008

goto exit


:Run Windows Vista specific commands here.

echo Windows Vista

goto exit


:Run Windows Server 2003 specific commands here.

echo Windows Server 2003

goto exit


:Run Windows XP specific commands here.

echo Windows XP

goto exit


:Run Windows 2000 specific commands here.

echo Windows 2000

goto exit


:Run Windows NT specific commands here.

echo Windows NT

goto exit


echo Machine undetermined.



Thursday, November 18, 2010

Oracle: Rename a column in a table

Oracle provides "alter table" syntax to rename data columns in-place in this form:


Here are the example of Oracle "alter table" syntax to rename data columns:


Saturday, November 13, 2010

Dos Command to read JDK Path from registry

These lines of code will get the JDK path from registry:

set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit
set Cmd=reg query "%KeyName%" /s
for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JVM_HOME=%%j
echo Path is : %JVM_HOMPublish PostE%

Wednesday, November 10, 2010

Create Dependencies between Windows Services

The following steps need to be performed in order to create a dependency.

1-Backup your current registry settings.

2-Run 'regedit' to open your registry.

3-Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services and locate the
service that you need to set a dependency for.

4-Open the 'DependOnService' key on the right side. If the selected service does not have a 'DependOnService' key, then create one by right-clicking and selecting New > Multi-String Value.

5-In the value field, enter the names of all services that the current service will depend on. Each service name must be entered properly and on a separate line.

6-Click OK, close your registry and restart your machine.

Thursday, September 30, 2010

Create Zip file of resources using Maven Assembly Plugin

If you have some resources (xml files, properties files etc) that contains project properties to be substituted before generating the zip package of those resources. Probably Maven is pretty helpful to create it. For example you have some paths of DTD schema in your xml files that you need to resolve before generating the deployable resource package.
You need to use Maven Assembly plugin to generate a zip file. You have to create an assembly descriptor file that you will include in your POM file.
The assembly descriptor will look like. you can save it as (zip-descriptor.xml)

<assembly xmlns=" " xmlns:xsi=" "
xsi:schemaLocation=" " >

<includeBaseDirectory >false </includeBaseDirectory >
<formats >
<format >zip </format >
</formats >
<fileSets >
<fileSet >
<directory >directory-name </directory >
<outputDirectory > </outputDirectory >
<filtered >true </filtered >
</fileSet >
</fileSets >
</assembly >

your POM file will look like. (POM.xml)

<project xmlns=" " xmlns:xsi=" "
xsi:schemaLocation=" " >

<modelVersion >4.0.0 </modelVersion >
<groupId >iceland-picking </groupId >
<artifactId >iceland-picking </artifactId >
<version >0.0.1-SNAPSHOT </version >
<packaging >pom </packaging >
<name >iceland-picking </name >

<prerequisites >
<maven >2.2.0 </maven >
</prerequisites >

<properties >
<product.codename >codename </product.codename >
< >product name </ >
<product.version >${project.version} </product.version >

<model.codename >${product.codename} </model.codename >
< >${ } </ >
<model.version >${project.version} </model.version >

<metabase.version >1 </metabase.version >
<database.version >1 </database.version >
</properties >

<build >
<plugins >
<plugin >
<groupId >org.apache.maven.plugins </groupId >
<artifactId >maven-assembly-plugin </artifactId >
<configuration >
<descriptors >
<descriptor >zip-descriptor.xml </descriptor >
</descriptors >
<finalName >this will be the name of the output zip file </finalName >
<appendAssemblyId >false </appendAssemblyId >
</configuration >
<executions >
<execution >
<id >make-assembly </id >
<phase >package </phase >
<goals >
<goal >single </goal >
</goals >
</execution >
</executions >
</plugin >
</plugins >
</build >
</project >

For more details please visit the following Maven link:

Friday, September 24, 2010

ORA-01000: maximum open cursors limit exceeded

If you are getting ORA-01000 exception, it means you need to review your design or you need to optimize your code. You need to make sure that all the open cursors are being closed after they are finished being used in application.

To check amount of open cursors in Oracle simple run this query:

select count(*) from v$open_cursor;

To increase/decrease the amount of open cursors limit run the following query:

ALTER SYSTEM SET open_cursors = 1000 SCOPE=BOTH;

OPEN_CURSORS sets the maximum number of cursors each session can have open, per session. For example, if OPEN_CURSORS is set to 1000, then each session can have up to 1000 cursors open at one time. If a single session has OPEN_CURSORS # of cursors open, it will get an ora-1000 error when it tries to open one more cursor.

The default value for OPEN_CURSORS is 50, but Oracle recommends that you set this to at least 500 for most applications. Some applications may need more, eg. High volume web applications.

Only increase the OPEN CURSOR limit if your application really needs it, otherwise focus on releasing the unused cursors in your code. For example, In Java close ResultSet or Statement or Connection object as soon as you are finished with them.

Friday, September 3, 2010

Default Argument Value for Methods

Like in C++, C#, PHP or SQL we can provide the default value for the argument that will be used in case when value is not supplied during method/function call. For example the following function declaration in C++:

void int someFun(int a, int b =0) {
// some implementation here...

In the above function the last argument has a default value of 0, and it will be used when we will call this function by providing only one parameter, like;
The above function call will give value 5 to argument “a” and 0 for argument “b”.
The same function can be called to provide both of the values, like:
Fortunately/Unfortunately you can not declare a function/constructor with default values for arguments because experts say this is a bad implementation design. If you have to achieve the same kind of functionality the better way is to declare overloaded methods and call one with default value in other. For example:

void int someMethod(int a, int b ) {
// some implementation here...
void int someMethod(int a) {
// call overloaded method with default value of the argument
someMethod(a, 0);

Thursday, August 12, 2010

SQL SERVER: Creating Comma Separate Values List from Table Column

There are two ways to generate a comma separated list from a table column. First is to manually concatenate the result and the second that is more sophisticated is to use the built-in function COALESCE of SQL Server.

Example Problem:
For example you have a table named COUNTRY that has a column named NAME, and you want to generate a comma separated list for countries.

Solution 1:
This is the simple but not the smartest way to implement it:

SET @listStr = ''
SELECT @listStr = @listStr + ISNULL(NAME,'') + ','
SELECT SUBSTRING(@listStr , 1, LEN(@listStr)-1)

Solution 2:
This is the smartest way:

SELECT @listStr = COALESCE(@listStr+',' , '') + NAME
SELECT @listStr

Monday, August 2, 2010

Javascript: Checkall/Uncheckall feature in the enclosing Form

on the web page dynamically generated, I am having different number fo forms and in each form I have a list of checkboxes genererated dynamically.
The number of textboxes in a form may varry, but in each form the checkbox Id/name will have a certain prefix to identify.
The following piece of Java Script code can be used to checkall/uncheckall the checkboxes in a specific form on some event(button, checkbox or any other javascript event)

Simply place the following piece of code in the head section of your web page:

*Prototypes for JS functions
String.prototype.startsWith = function(str){return (this.match("^"+str)==str)}
String.prototype.endsWith = function(str){return (this.match(str+"$")==str)}

*Check/Uncheck all the checkboxes in the selector column of a report.
function getArray(formName,inputtype, prefix)

var checkBoxesArray=new Array();
var count = 0;
for(i=0; i < formName.elements.length ; i++)
var elmNameStr = formName.elements[i].name.toString();
var elmName =formName.elements[i];

//alert (elmName+ " :: elementName (startsWith): "+ elmNameStr.startsWith(prefix));

if(formName.elements[i].type==inputtype && elmNameStr.startsWith(prefix))
checkBoxesArray[count++] = elmName;
//alert(checkBoxesArray.length + " checkboxes found");
return checkBoxesArray;

function checkall(elem,flag,pattren)
var form = findParentForm(elem);

var arrayCheckboxes = getArray(form,"checkbox", pattren);

for ( i = 0 ; i < arrayCheckboxes.length ; i++) {
arrayCheckboxes[i].checked = flag;

function findParentForm(elem){
var parent = elem.parentNode;
if(parent && parent.tagName != 'FORM'){
parent = findParentForm(parent);
return parent;


To call the checkall functionality, simply call "checkall" function as:

onclick="javascript:checkall(this, this.checked,'butt-');"

@param1: Element Id you are calling on the function, usually a checkbox
@param2: Current state of check box, whether the checkbox state is checked or unchecked. If this checkbox is checked then all the associated checkboxes should also be checkd and vice versa
@param3: String prefix for the checkbox Id/name pattern to identify the appropriate list.


<form name ="formName0">

check/uncheck all: <input type ="checkbox" name ="test" onclick="javascript:checkall(this, this.checked,'butt-');"/> <br/>
Must Change State: <br/>
<input type ="checkbox" name ="butt-1234"/>
<input type ="checkbox" name ="butt-2141"/>
<input type ="checkbox" name ="butt-3_abh"/>
<input type ="checkbox" name ="butt-asgas"/>
<input type ="checkbox" name ="butt-0"/>
Must have ignored:<br/>
<input type ="checkbox" name ="abc"/>
<input type ="checkbox" name ="def"/>

<h3> Form 2 </h3>
<form name ="FormName1">
<div id ="asda" name ="divName">
check/uncheck all: <input type ="checkbox" name ="test" onclick="javascript:checkall(this, this.checked,'selected-');"/> <br/>
Must Change State: <br/>
<input type ="checkbox" name ="selected-1af"/>
<input type ="checkbox" name ="selected-wf2"/>
<input type ="checkbox" name ="selected-3_abh"/>
<input type ="checkbox" name ="selected-asgas"/>
<input type ="checkbox" name ="selected-0"/>
Must have ignored:<br/>
<input type ="checkbox" name ="selected_sabah"/>
<input type ="checkbox" name ="abnsd"/>


Friday, July 30, 2010

SQL Server: To check all the advanced configuration of the SQL Server

Run the following database script to check all the advanced configuration options

EXEC sp_configure 'Show Advanced Options', 1;
EXEC sp_configure;

Thursday, July 29, 2010

Javascript: How to Find the enclosing/parent FORM Element

I was working on a project and came across a situation where we have more than one forms being generated dynamically in one page. And each form contains lots of input fields. To identify the enclosing/parent form element on some action of input tags, I used the following code:

Put these two javascript functions in script tag under head section of your page:

function findParentForm(elem){
var parent = elem.parentNode;
if(parent && parent.tagName != 'FORM'){
parent = findParentForm(parent);
return parent;

function getParentForm( elem )
var parentForm = findParentForm(elem);
alert("Form found: ID = " + + " & Name = ";
alert("unable to locate parent Form");


Here is the example to call this code:

<h3> Form 1 </h3>
<form name ="formName1" id ="formId1">
<input type ="button" name ="button1" value="button1" onclick="javascript:getParentForm(this);"/> <br/>

<h3> Form 2 </h3>
<form name ="FormName2" id ="formId2">
<div id ="asda" name ="divName">
<input type ="button" name ="button1" value="button2" onclick="javascript:getParentForm(this);"/> <br/>

Friday, July 23, 2010

Oracle: Generate SQL script to drop all tables of any database

In oracle there is no option to drop all the user tables, but you can achieve this by generating a scrip and run that script.
To generate a script for dropping all the user tables, simply run this query and then run the result/output of this query.

FROM user_tables;

Wednesday, July 21, 2010

Eclipse getting Out of Memory

I installed latest version of JDK 1.6.21 and latest eclipse Halilos version to Windows 7 (32bit). Eclipse started crashing again and again after few minutes, giving me the out of Memory issue in logs.

Here is the exception log:

!ENTRY org.eclipse.ui 4 0 2010-07-21 09:08:30.662
!MESSAGE Unhandled event loop exception
java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(
at java.lang.ClassLoader.defineClass(
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(
at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at org.eclipse.wst.sse.ui.StructuredTextEditor.createActions(
at org.eclipse.ui.texteditor.AbstractTextEditor.createPartControl(
at org.eclipse.ui.texteditor.StatusTextEditor.createPartControl(
at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.createPartControl(
at org.eclipse.wst.sse.ui.StructuredTextEditor.createPartControl(
at org.eclipse.ui.part.MultiPageEditorPart.addPage(
at org.eclipse.ui.part.MultiPageEditorPart.addPage(
at org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart.addSourcePage(
at org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart.createPages(
at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(
at org.eclipse.ui.internal.EditorReference.createPartHelper(
at org.eclipse.ui.internal.EditorReference.createPart(
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(
at org.eclipse.ui.internal.PartPane.setVisible(
at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(


After struggling with this, I found this issue is due to the latest JDK v1.6.21. Best is to use the stable version of JDK that is: JDK v 1.6.20 and configure it accordingly.
Hopefully it will resolve the issue, if still getting the issue add following line after "-vmargs" to your eclipse.ini file:
The eclipse.ini file can be found under eclipse directory. It will be someting like this:





C:\Program Files\Java\jdk1.5.0_22\bin







Wednesday, July 14, 2010

Java Web Service: Developing SOAP Based Web Service via Apache Axis2

Web service is a distribution software/application component that communicates using open protocols is self contained, self describing and can be discovered by UDDI (Universal Description, Discovery and Integration). Web Services can be used by other applications, or you can say other applications consume the web services. XML is the basis of the web services. XML is a language used to communicate between the different languages. Web Services are language independent and platform independent because all the vendors are agreed to use the common protocols and common way of communication using XML.
There are two main models for web services development in Java, REST based web services and SOAP/WSDL based web services.

REST based Web Services:- REST (REpresentational State Transfer) are resources in which every process is modeled as a unique URI. The protocol used in REST based web services is HTTP. These are not as secure, as flexible, as SOAP based web services. And only supports HTTP protocol.
SOAP/WSDL based Web Services:- SOAP/WSDL-based web services uses Java utilities create a WSDL file based on the Java code in the web service. The WSDL is exposed on the net. Parties interested in using the web service create a Java client based on the WSDL. Messages are exchanged in SOAP format. The range of operations that can be passed in SOAP is much broader than what is available in REST, especially in security. SOAP-based web services are suitable for heavyweight applications using complicated operations and for applications requiring sophisticated security, reliability or other standards-supported features. They are also suitable when a transport protocol other than HTTP has to be used.

Apache Axis2 is an open-source implementation of the SOAP (Simple Object-Access Protocol) submission to the W3C. Axis2 not only supports SOAP 1.1 and SOAP 1.2, but it also has integrated support for RESTful web services.

We are going to develop a simple web service using Apache Axis2 using eclipse and Tomcat 6 as server.

Setting up the Environment:
Creating a Bottom up Java Bean Web Service:

Step 1:
First step is to configure the Axis2 with tomcat. To accomplish this unzip/extract the downloaded Axis version at any location of your hard drive. I am using this path for this example: C:\axis2\axis2-1.5

Then Open Eclipse and open:
Window -> Preferences -> Web Services -> Axis2 Preferences

Select the Axis2 Runtime tab and point to the correct Axis2 runtime location and click Apply and then Ok.

Step 2:
Now we need to create a project with the support of Axis2 features. Open File -> New -> Other... -> Web -> Dynamic Web Project

Click Next and provide project name as CalculatorWebService (you can use any name). Please select the following configurations:
“Apache Tomcat v6.0” as Select Target runtime.
“2.5” as Dynamic web module version
For Configuration, Press the Modify button.

Now tick the check boxes named as “Axis2 Web Services” and select OK.

After this you will be back on the New Dynamic Web Project. Click Finish. A new project will be created.

Step 3:
Now add a new package (myservices) and a plain Java class (Calculator). This Calculator class will contain methods that we will expose as web service. The methods we want to expose as web service must have public access.

Step 4:
Now Select, open File -> New -> Other... -> Web Services -> Web Service

Click Next and you will be on the following screen. And make sure you Server rumtine is Tomcat v6.0 Server and Web Service Runtime should be Apache Axis2, if not you can configure these by clicking on the hyperlinks. For example to configure Web Service Runtime, click on the hyperlink highlighted as following.

And it will open a new screen to configure Apache Axis 2 runtime for you. Select Apache Axis2 from the list and click ok.

You will be back on Web Service Screen, click Next.

Again click Next.

Now Click Start Server button.

Now Click Finish. Your web service is created for your Calculator class and it is published to your Tomcat Server.
Step 5:
Right Click on the web service project and run as server.

Choose the server and click Finish.

You will see the following page in your integrated browser of eclipse.

Click on the services link encircled above and you can see your calculator service as following.

If you click on the Calculator link encircled above, you can see the WSDL generated by your web service. This WSDL you will use to create a wb service client. Please copy the link of WSDL:

The next step is to create a Web Service Client to test this web service.

Create a Web Service Client:
To create a web service client and test the web service, we will create a new project and will test this web service. Open File -> New -> Other... -> Web Services -> Web ServiceClient

Click Next.

Paste the WSDL path in the service definition box and make sure you have the correct configurations as displayed in above snapshot. And click Next.

Now leave the default configurations on this screen and click Finish. I will generate a new project that will contain the Stub class that we can use to call the methods of web service.
Add a new class in the client project to test the web service methods like shown in the following snapshot.

package myservices;

import java.rmi.RemoteException;
import org.apache.axis2.AxisFault;

public class CalculatorTestClient {

* @param args
* @throws RemoteException
public static void main(String[] args) throws RemoteException {
//Step 1: create an object of Stub class that is generated.
CalculatorStub stub = new CalculatorStub();
//Step 2: Web Service Client has created inner classes in CalculatorStub for each of the web service method.
// We need to create the object of these classes to utilize the web service method.
CalculatorStub.Add add = new CalculatorStub.Add();
// Step 3: set the values for parameters for the web service method to call
// Step 4: Now call the web service method using the stub object and assign it to specific response variable.
CalculatorStub.AddResponse resp = stub.add(add);
// Step 5: Finally call the get_return method to retrieve the final result from response object.
System.out.println(" Result for 45.78 + 12.34 = "+resp.get_return());
}// end main

} // end class
Now finally, run this client as plain java program. Right Click inside the Java class-->Run as-->Java Application. You can see the results on the console.

You can also use Netbeans to create SOAP based Apache Axis2 Web Services. For this please visit the following tutorial.

Thursday, July 8, 2010

Installation of Subclipse and Connecting to Repository

Installation of Subclipse:

This blog will describe the installation of Subclipse directly through Eclipse. Please note, for safety purposes, a separate instance of eclipse should be installed prior to installation of the repository.

Information on Subclipse can be found here:

And new versions of Eclipse can be founder here:

At the writing of this document, I am using Galileo release of Eclipse (Version 3.5.2).

Step 1
Goto Help menu, and select Install New Software...

Step 2
Add the site where Subclipse can be downloaded from.

Step 3
Select the checkbox that is next to the Subclipse name. This will install all items required for Subclipse, and an additional merge utility.

Step 4
Review the install details, and click next. Then accept the license agreement presented after reviewing the install details.

Step 5
Once completed, and you hit next, the download of the plugin will occur.

Conclusion: Restart Eclipse...

Connecting to Repository:

Next step is to download the repository of your projects source. Unlike CVS, SVN represents branches and tags as files in the folder structure. We want to be careful not to check out the entire repository. If the entire repository is checked out, a representation of every tag and branch ever made for the application will be downloaded as a local copy to the hard drive. This could consume a lot of disk space very carefully.

Create a new project in Eclipse from the SVN repository. Select "Checkout Projects from SVN." Then click next.

If you do not have any repository yet, select "Create a new repository location" then click next.

And provide the SVN repository path and click Next and then Finish.

Select the appropriate project listed (Not Shown here) and click Next.
Create a new project to add to your workspace. Ensure "Check out HEAD revision_"_ and check out as a new project in your workspace, or use the New Project Wizard (not shown) to create a new project.

Use the default workspace, or one you already have defined.

The SVN Repository checkout will start right away.

Sysdeo Eclipse Tomcat Launcher plugin

Plugin features

  • Starting and stopping Tomcat 4.x, 5.x and 6.x

  • Registering Tomcat process to Eclipse debugger

  • Creating a WAR project (wizard can update server.xml file)

  • Adding Java Projects to Tomcat classpath

  • Setting Tomcat JVM parameters, classpath and bootclasspath

  • Exporting a Tomcat project to a WAR File

  • Capability to use a custom Tomcat classloader to load classes in several java projects at the same classloader level than classes in a Tomcat project, see readmeDevLoader.html (Thanks Martin Kahr)

    Download Link:

Wednesday, June 30, 2010

Apache Tomcat Version 7.0 is Released

The new features provided in Apache Tomcat 7, including the new features in the Servlet 3.0, JSP 2.2 & EL 2.2 specifications, improvements in memory leak detection and prevention, new security features that can prevent CSRF attacks and session fixation attacks and a host of other new features.

Here is the official download link: