Wednesday, September 17, 2014

How to Resolve java.lang.NegativeArraySizeException in Spring


When will you get this Exception?

I was getting this exception when I start my spring application. I was searching the web for any better solution but nothing worked out.
Later I was able to remember the mistake which I have done.

What mistake I have done?
I have defined a property in my class and defined the same in the bean definition file as well. I have copy pasted my bean file into the tomcat.
Later I have removed my property from the java class file and I have not removed the property entries from the bean definition XML file.

What is the reason for the error?
We will get this exception when we have defined a property for a Class later which we have removed those properties from the class.

Solution
Remove the unwanted property definition from the bean definition file and redeploy bean definition XML files.

Friday, September 12, 2014

How to Resolve java.net.BindException: Address already in use: JVM_Bind

I have encountered this issue when I was starting my tomcat.

Actual Exception Trace:

SEVERE: StandardServer.await: create[8005]:
java.net.BindException: Address already in use: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)

Reason:

The port 8005 is already binding by some other application and that is why we are not able to use it.

Solution:

Change the port number 8005 in tomcat server's server.xml file as below:
<Server port="8005" shutdown="SHUTDOWN"> into <Server port="8006" shutdown="SHUTDOWN">

Monday, September 8, 2014

How to unlock table in SQL

INTRODUCTION

Sometimes when multiple users perform operations like update/delete on a table, there is a chance for a table lock.

ISSUE

SQL table is locked.

SOLUTION

To unlock all the locked tables, need to login as an ADMIN user.

Step 1

Check if the Package or table are locked using the below query

SELECT b.object_name, a.session_id, a.oracle_username, a.os_user_name, a.process, a.locked_mode
FROM v$locked_object a, all_objects b
WHERE a.object_id = b.object_id;

Step 2

Get the serial number for the session based on the session id got from above query.
SELECT SID, serial#, ownerid, status, server, username, osuser, process, machine
FROM v$session
WHERE SID = 'Session id from above query';

Step 3

Kill the session below command.
ALTER SYSTEM KILL SESSION 'Sid from query, Serial# from Query 2';
Example:
1) SELECT SID, serial# FROM v$session WHERE SID in (select session_id from v$locked_object);
2) ALTER SYSTEM KILL SESSION '8,19087';

ALTERNATE SOLUTION

We can also unlock the table by below approach
select a.session_id,a.oracle_username, a.os_user_name, b.owner "OBJECT OWNER", b.object_name,b.object_type,a.locked_mode from
(select object_id, SESSION_ID, ORACLE_USERNAME, OS_USER_NAME, LOCKED_MODE from v$locked_object) a,
(select object_id, owner, object_name,object_type from dba_objects) b
where a.object_id=b.object_id;

--To check
SELECT object_id FROM dba_objects WHERE object_name=’MYOBJECT';
SELECT sid FROM v$lock WHERE id1=360254;
ALTER SYSTEM KILL SESSION '3434,92193' ;

Saturday, September 6, 2014

How to Configure Multiple Tomcat Server in Same Machine

INTRODUCTION

This post will help to us to configure multiple tomcat server into the same machine/server.

Sometimes there is a need for setting up multiple tomcat to debug the application.

I came across this situation I wanted to debug two different version of my application at same time and check the value for an object.

Following are the steps to achieve it.

Step 1

Install tomcat with two different names as below
  1. C:\Tomcat6.0-1 (with http port 8080)
  2. C:\Tomcat6.0-2 (with http port 8090)

Step 2

Open the C:\Tomcat 6.0-2\conf\server.xml and modify the below lines.
  1. Change  port="8006" on <Server port="8005" shutdown="SHUTDOWN">
  2. Change  port="8010" on <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Step 3

Don't do any change on C:\Tomcat6.0-1. By default settings can be used.
  <Server port="8005" shutdown="SHUTDOWN">
  <Connector port="8080" protocol="HTTP/1.1" >
  <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Now you can able to connect the application as below.
Now Tomcat-1 can be connected using URL: http://localhost:8080/<your-application>
and Tomcat-2 can be connected using URL: http://localhost:8090/<your-application>

Friday, September 5, 2014

[SOLVED] java.sql.SQLException: ORA-01658: unable to create INITIAL extent for segment in tablespace


ISSUE

ORA-01658: unable to create INITIAL extent for segment in tablespace USER_DATA

REASON

If there is no enough space in the tablespace (e.g: USER_DATA), it will throw this error.

SOLUTION

We are trying to extend the space using 'autoextend' instead of setting fixed size. Login as sys_dba user and follow the below steps.

STEP 1

Find the list of tablespaces already available by below query.
select 'alter database datafile '|| file_name|| ' '|| ' autoextend on maxsize unlimited;' from dba_data_files;

You will get the below results:
alter database datafile C:\ORACLEXE\APP\ORACLE\PRODUCT\11.2.0\SERVER\DATABASE\LOB_DATA  autoextend on maxsize unlimited;

alter database datafile C:\ORACLEXE\APP\ORACLE\PRODUCT\11.2.0\SERVER\DATABASE\USER_DATA  autoextend on maxsize unlimited;

alter database datafile C:\ORACLEXE\APP\ORACLE\PRODUCT\11.2.0\SERVER\DATABASE\INDEX_DATA  autoextend on maxsize unlimited;

STEP 2

Run the below query which will set the tablespace to autoextend whenever the actual space is filled.
alter database datafile 'C:\ORACLEXE\APP\ORACLE\PRODUCT\11.2.0\SERVER\DATABASE\LOB_DATA'  autoextend on maxsize unlimited;

alter database datafile 'C:\ORACLEXE\APP\ORACLE\PRODUCT\11.2.0\SERVER\DATABASE\USER_DATA'  autoextend on maxsize unlimited;

alter database datafile 'C:\ORACLEXE\APP\ORACLE\PRODUCT\11.2.0\SERVER\DATABASE\INDEX_DATA'  autoextend on maxsize unlimited;

Wednesday, August 13, 2014

Handling Attributes of an Element in JQuery

INTRODUCTION

Attributes define the actual element's style, id etc for any element. For example, element <div> will have attributes like.
  • id
  • style
  • align
  • lang
  • title
Now we will see how can we get the existing value of these attribute and also how to reset the values by the following example.

Example Program

attributes.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Attributes Setter/Getter</title>
</head>
<script type="text/javascript" src="lib/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="js/attributes.js"></script>

<body>
 <div id="myDiv" style="background: red; width: 200px" align="left" lang="en" title="MySampleDiv">MyDivContent</div>
 <input type="button" id="btn" value="Attributes" />
 <br>
 <br>
 <table border="1">
   <tr>
     <td id="td1"></td>
     <td id="td2"></td>
     <td id="td3"></td>
     <td id="td4"></td>
   </tr>
 </table>

</body>
</html>

attributes.js
$(document).ready(function() {
 $("#btn").click(function() {
   // Get the existing attribute values
   $("#td1").text($("#myDiv").attr("style"));
   $("#td2").text($("#myDiv").attr("align"));
   $("#td3").text($("#myDiv").attr("title"));
   $("#td4").text($("#myDiv").attr("lang"));

   // Reset the existing attribute values
   $("#td1").text($("#myDiv").attr('style', 'background:blue'));
   $("#td2").text($("#myDiv").attr("align", 'right'));
   $("#td2").text($("#myDiv").attr("title", "NewDivValue"));
   $("#td2").text($("#myDiv").attr("lang", "jp"));

 });
});

How to handle styles in JQuery

In this example, we will learn how to add or remove styles in Jquery.

Syntax to Apply Style

$("#elementId").addClass("cssClassName");

Syntax to Remove Style

$("#elementId").removeClass("cssClassName");

Example Program

addRemoveCss.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JQuery CSS Example</title>
<link type="text/css" href="styles/addRemoveCss.css" rel="stylesheet" />
</head>
<script type="text/javascript" src="lib/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="js/addRemoveCss.js"></script>

<body>
 <input type="button" id="changeColorBtn" value="Change Color" />
 <br>
 <br>
 <div id="myDiv" style="width: 375px">Div</div>
</body>
</html>

addRemoveCss.css
@CHARSET "ISO-8859-1";

.redColor {
 background: red;
}

.blueColor {
 background: blue;
}

addRemoveCss.js
$(document).ready(function() {
 $("#changeColorBtn").click(function() {
   $("#myDiv").addClass("redColor");
   alert("redColor added");
   $("#myDiv").addClass("blueColor");
   alert("blueColor added.....");
   $("#myDiv").removeClass("blueColor");
   alert("blueColor removed");
 });
});

How to enable or disable an element using JQuery

Syntax to Enable An Element

$('#submitbutton').prop("disabled", false);

Syntax to Disable An Element

$('#submitbutton').prop("disabled", true);

Example Program

enableDisableElement.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JQuery Example</title>
</head>
<script type="text/javascript" src="lib/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="js/enableDisableInJQuery.js"></script>

<body>
 <table>
   <tr>
     <td><input type="text" id="myTextBox" value="Hi Dear" /></td>
   </tr>
   <tr>
     <td><input type="button" id="disableTxt" value="Disable Text" /></td>
     <td><input type="button" id="enableTxt" value="Enable Text" /></td>
   </tr>
 </table>
</body>
</html>

enableDisableElement.js
$(document).ready(function() {
 $("#disableTxt").click(function() {
   $("#myTextBox").prop("disabled", true);
 }),

 $("#enableTxt").click(function() {
   $("#myTextBox").prop("disabled", false);
 });
});

Friday, July 11, 2014

Online Tools

INTRODUCTION

This post will give all the available online tools for various technologies. These web tools help the developers to develop the program without installing the software.

HTML EDITORS

CSS EDITORS

XML to JSON CONVERTERS

DATABASE TOOLS

UML DIAGRAM TOOLS

REGULAR EXPRESSION TOOLS

JAVASCRIPT TOOLS

DRAWING TOOLS

Unix Commands

GENERAL COMMANDS

1. Check all environment Variables
$ env
$ printenv
2. Grep Command
grep '2012-03-27' /path/tomcat/apache-tomcat-6/logs/catalina.out | grep '9927773'

SVN COMMANDS

1. Checkout a code base
$ svn checkout <checkout url>

OR
$ svn co <chekout url>
2. Update a code base
$ svn update
3. Check-in/Commit files
$ svn ci -m “commit message”
4. Check current svn check-in details
$ svn info

COPY COMMANDS

1. Copy file from one server to another
We have a file (/prod/myfile.zip) in Server 1 and needs to be copied to Server 2 (/data/test/)
Server 1 (ip: 10.5.55.20) - Source Server
  username: ranjith
  password: sekar   
Server 2 (ip: 10.3.33.90) - Destination Server
  username: anbu
  password: selvan
Now login to Server 1 and enter below command
$ scp /prod/myfile.zip anbu@10.3.33.90:/data/test/
$ <enter password: selvan>

DELETE COMMANDS

1. Delete a folder in current directory
$ rm -rd <folder>
2. Delete a folder and its sub folders
$ rm -rf <folder>

FILE MANIPULATION COMMANDS

1.View Content of a file (less command)
$ less <filename>

1.1 To traverse the file

$ spacebar => Next page
$ b => previous page
$ g => top of the page
$ shift + g -=> bottom of the page

1.2 To search a string

type /<string> and enter
2.Delete a content of file
cat /dev/null &gt; processLog.txt
3. Create shortcut for a file.
ln -fs /folder1/folder1-subfolder/index.html /folder2/folder2-subfolder/