Friday, March 28, 2014

Unable to connect to database using JDBC driver


I was trying to connect to a database from Cordys using jdbc driver. It gives an exception called "Configuration Validation was not successful". Please note below




When I expand that error I could understand the reason was "Unable to locate the path of the driver" basically "ClassNotFound" exception.





The solution to this would be to set the CLASSPATH environment variable to the required jar path. Here in this case it would be ojdbc14.jar which holds the necessary class files. It would be done in the below mentioned steps

Step 1 : Locate ojdbc14.jar file. If you have oracleXE installed in your environment it would be present in the below given location but if you don't have oracleXE installed then you would have to download this jar and copy the path from the explorer.



Step 2 : Set the environment variables using the jar path from step 1.

Since the above environment variables belong to system you might have to restart your system. However I have read at many places saying Windows 7 would not need a restart to have this environment variables to be set, but I did not want to take a chance and I restarted. It worked.


Wednesday, March 26, 2014

Eliminate "E" from the amount string to show only the amount without "E" (8.23452345678E9 as 8234523456.78)

 Normally a beginner in development will end up storing the amount in Double variable which will eventually store in "E" format (for ex., 8.23452345678E9) and when we deal with XML's we end up sending the same value to the XML Tag, hence rendering in a front end would be similar which is not suitable for a user to view. Hence this situation has to be avoided.

First resolution would be "Try avoiding usage of Double variables for amount fields instead use BigDecimal" if you have option to do that.

What if the above change is something which is not in your hands (may be because of many reasons like its being used at many places I cannot change the return type of the function, its a third party webservice it is giving like that I cannot change it etc.,)? 

You basically have to convert this amount which is in the above mentioned format into a BigDecimal format and eventually update the xml tag with the value that you have converted.

This can be done as below

String amountInString="8.23452345678E9";
System.out.println(String.valueOf(BigDecimal.valueOf(Double.valueOf(amountInString))));

Courtesy : Learnings from GIB Project
________________________________________________________________________________
Continuation based on Comments :

If you do not want to get this E format itself then you can follow the below :

String str= "2000100010.1245" ;
BigDecimal bg=new BigDecimal(str);
System.out.println(bg.toString());

if the decimal value has to be restricted to only two digits after decimal then we can use Scale method :

System.out.println(bg.setScale(2, RoundingMode.CEILING));

Result : 2000100010.13

If any calculations have to be made with such large numbers then big decimal has Add,subtract etc methods

Thursday, March 20, 2014

Unable to connect to Oracle server from network computer using sql developer

Problem statement :

In a normal web based application and where many developers would be working on a single environment having an oracle server in each is not at all suggestible hence the approach would be centralized. Oracle server will be installed in one machine and developer would connect to that server using clients such as sql developer, toad etc., and retrieve data using queries. This post is about problem encountered while trying to connect to oracle server using sql developer from other computer in the same network (i.e., machine where the oracle server is installed and machine from where the accessing is being done are connected via LAN). Now the problem I am facing while connecting to an oracle instance in server is "The Network Adapter could not establish the connection". A Sample screenshot gives a brief picture of the problem which I was facing,


Resolution :

The problem in my case was the firewall. The Firewall of server where oracle has installed is stopping my sql developer to connect to the server. Hence there has to be exception added for the firewall to allow this communication. This is done using the following approach.

The approach I have tried giving as depth as possible the steps of which are given below,

Below steps have to be performed in the server where oracle is installed (the overview of the resolution is to add 

Step 1 : Open Windows firewall from control panel and locate a link which says "Allow a program or feature through Windows Firewall", this is highlighted in the below picture.

Step 2 : Once you click on that you would see something similar to below. Please click on the "Change settings" and click on "Allow another program".

Step 3 : sql developer would communicate with server using tnslistner which listens if there is any incoming signal to the server. Hence this has to be given as an exception for windows firewall. Locate to the file where tnslistner.exe is available in the server (In my case it was "C:\oraclexe\app\oracle\product\10.2.0\server\BIN"). And select TNSLSNR.exe file from the pop up.
Once you say "Add" this exception will be added to the windows exception list.

Then click on "Ok" from the screen and that's it. This worked in my case. The final response of sql developer while connecting is 



Tuesday, March 11, 2014

My Gateway is unable to log in filesystem

Problem statement :

I have a custom gateway "sch.oauthint.OAuthHandler.wcp" and I can only debug via logging into filesystem (I know only this way of debugging :P unlike webservices which I can do it via eclipse). So I have encountered a strange problem as I saw there is an error in my application and I want to log. Whenever there is any error it logs in a file which starts lik "Gateway...." in my cordys logs folder but in this scenario I was not able to see the file at all. Hence a blocker for me to understand what is the issue. I have not observed this behavior when I do it in my local system. 

One Approach :

What our(me along with my colleague) understanding was that the user context with which it logs into file system was not having rights to write into file system and our understanding was right. Hence we need to give the rights to the folder "Logs" of the instance of cordys.

Below are the images which would help you in solving the problem :
First immediate task is to find out the user for your website. You can do it by going into IIS settings,


Default Web Site : Website where cordys is installed

You will be seeing "Authentication" as one of the artifact under IIS (highlighted)
Double click on that, You will be viewing a screen which is shown below








Now click on the Name which shows "Enabled" under status, in my case it was "Anonymous Authentication" now on the right side there are "Actions", click on the Edit to view the below screen.

 You will now be able to see what is the User with which it is trying to log.

"IUSR" in my case.Now the next immediate thing you have to do is to give the access permissions on folder "Logs" for this user. This step is shown below
Right click on the folder "Logs" under instance and click on sharing property. Give the access to the user you have found out above "IUSR" in my case.

You can view that in the following screen. 
When I have seen this option the access to the user "IUSR" was "Contribute"(I don't know what is the meaning of this option :P) but I have changed this setting to "Read/Write" which is when my problem got solved.


Note : However this was my approach of solving the problem. There might be different ways also to solve this problem (Windows user can be changed but I did not do that as this approach given me solution).