Tuesday, July 30, 2013

Solving jdbc.SQLServerException: The statement did not return a result set.

My stored procedure (SP) returns the last updated record from a table if totalAmount is not null or zero. The SP runs fine in SQL Server Management Studio.
When I run the same SP from my grails/java app, it throws the error "Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set."

This was because if totalAmount is null or zero, there is nothing to return. Therefore, I added an empty /null return. The code is shown below.

-- Save total_amount of every BU for that day
SELECT @totalAmount = SUM(total_amount) FROM settlement

IF (@totalAmount IS NOT NULL)
  -- Insert fields in to settlement_batch table 
  INSERT INTO settlement_batch (completed_time_stamp,       
         settlement_batch_number, status_time_stamp, 
         total_amount, updated_by_user_id, created_by_user_id, 
         date_created, last_updated, version)
  SELECT GETDATE(), MAX(ISNULL(settlement_batch_number,0)) + 1, 
         GETDATE(), @totalAmount, @currentUser, @currentUser, 
         GETDATE(), GETDATE(), 0
  FROM settlement_batch
  -- Get the settlement_batch_id of the last inserted record
  SET @new_settlement_id = IDENT_CURRENT('settlement_batch');

  -- Return the last inserted id in settlement_batch
  SELECT ISNULL(@new_settlement_id, 0) AS NewSettlementId
    SELECT NULL AS NewSettlementId

Wednesday, July 17, 2013

Change gitbash home directory

The simplest way is to change the property of the git bash.
Right click on Git Bash -> Properties
Change the "Start in" attribute to "%HOMEDRIVE%%HOMEPATH%\git" (without quotes) as shown in the figure below.

Publishing to Tomcat v6.0 Server at localhost has encountered a problem.

I run in to the following Tomcat server error while trying to build my application developed in Java (using Eclipse IDE).

Tuesday, July 16, 2013

Target runtime Apache Tomcat v6.0 is not defined

Posted on 

I was upgrading the tomcat in my eclipse from version 6 to 7. Servers were added, old servers were removed. Tomcat 6 installed. But the server is not starting because of the following error.
Target runtime Apache Tomcat v6.0 is not defined.    <project name>        Unknown    Faceted Project Problem
It keeps my old server entry for the project.
We need to right click on the project, properties and Targeted Runtimes. Uncheck the old entry and enable the new entry. This should solve this error.
Targeted Runtimes
Targeted Runtimes
Still server is facing some other issue. Need to check up.

Windows 8 - Cannot Save on 'Hosts'

Article by http://www.petenetlive.com/KB/Article/0000674.htm


Windows did this with Windows 7 (and Vista). If you attempt to edit the hosts file you will see the following.
Hosts - You don't have permission
You don't have permission to save in this location. Contact the administrator to obtain permission. Would you like to save in the My Documents folder instead?


1. You could run an admin command window, and use the EDIT command, but Notepad is easier. Open the Apps page (Windows Key+Q) > Locate Notepad and right click it > Run as Administrator.
Note: YES Even if you are logged in as an administrator.

Windows 8 Run Notepad as Administrator

2. Now you can open the hosts file (make sure you change the file type to all files or notepad wont see it!). And you can then edit the file and save the changes.

Windows 8 Save the hosts file

Making VMware Server 2 work on Windows 8

Follow the following steps:

  1. Install VMware server
  2. Open regedit and look for this address
    1. HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\VMwareHostd\DependOnServiceand Remove "ProtectedStorage" from the list.
  3. Open CMD and write the followingsc create "VMware Host Agent" start=auto binPath="C:\Program Files (x86)\VMware\VMware Server\vmware-hostd.exe"
  4. Restart your computer
  5. Start the VMware by double clicking on the icon on the desktop "VMware Server Home Page"
  6. Log in. If you are not able to log in, use your "administrator" user's name and password. For more info, read this (http://helpdeskgeek.com/virtualization/vmware-server-web-access-default-username-and-password/)
  7. If you already have a VM installed and moved from another computer,
    1. Click on "Add Virtual Machine to Inventory"
    2. Browse and Select the .vmx file
    3. When it prompts you "msg.uuid.altered:This virtual machine may have been moved or copied. In order to configure certain management and networking features VMware Server needs to know which. Did you move this virtual machine, or did you copy it? If you don't know, answer "I copied it"." 
select "I Moved It" and click "OK"

8. If such error comes 
"Power On Virtual Machine" failed to complete.
If these problems persist, please contact your system administrator.
Details: Cannot open the disk 'C:\Virtual Machines\Windows 2003-002\Windows 2003-002.vmdk' or one of the snapshot disks it depends on.


Reason: Failed to lock the file.", delete the .lck file from the VM's folder. These files are the lock files that should only exist while your VM is powered on. Delete the .lck files and power the VM up.

Friday, July 5, 2013

Decoding/Converting .apk Files to Source Code

Procedure for decoding .apk files: a step-by-step method

* This article is written by a guy code named "prankul garg" in stackoverflow.com.

Step 1:

Make a new folder and put .apk file in it (which you want to decode). Now rename the extension of this.apk file to .zip (eg.: rename from filename.apk to filename.apk.zip) and save it. Now you get classes.dex files, etc. At this stage you are able to see drawable but not xml and java files, so continue.

Step 2:

Now extract this zip apk file in the same folder (or NEW FOLDER). Now download dex2jar from this linkhttp://code.google.com/p/dex2jar/ and extract it to the same folder (or NEW FOLDER). Now open command prompt and change directory to that folder (or NEW FOLDER). Then write dex2jar classes.dex and press enter. Now you get classes.dex.dex2jar file in the same folder. Then download java decompiler from http://java.decompiler.free.fr/?q=jdgui and now double click on jd-gui and click on open file. Then open classes.dex.dex2jar file from that folder. Now you get class files and save all these class files (click on file then click "save all sources" in jd-gui) by src name. At this stage you get java source but the xml files are still unreadable, so continue.

Step 3:

Now open another new folder and put these files
  1. put .apk file which you want to decode
  2. download apktool v1.x AND apktool install window using google and put in the same folder
  3. download framework-res.apk file using google and put in the same folder (Not all apk file need framework-res.apk file)
  4. Open a command window
  5. Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk
  6. apktool d "fname".apk ("fname" denotes filename which you want to decode)
now you get a file folder in that folder and now you can easily read xml files also.

Step 4:

It's not any step just copy contents of both folder(in this case both new folder)to the single one
and now enjoy with source code...