Saturday, July 10, 2010

How to find indexes for a table?

How can I find the indexes created on a table?

It is very easy to find out the indexes existing on a table. Before I did not know about this SQL statement I was thinking that it is going to be a gigantic task. But just the following statement did the trick.

In Oracle, there exists a table with the name "user_ind_columns" which contains 4 columns.
1 table owner
2 table name
3.index name
4.column name

What you need to do is --- just running an SQL statement against the database using this information.
Sample query to find table indexes and related information:
select table_name, index_name, column_name 
from USER_IND_COLUMNS
where TABLE_NAME='EMPLOYEE'


Note: Please leave your comments and make the valuable suggestions available to the world.

Friday, August 21, 2009

Enable remote desktop on LINUX system using VNC

set up required for enabling the remote desktop on LINUX machine using VNC

NOTE1: Enter all commands without the double quotes (")
NOTE2: if you encounter an error saying "command not found", just enter the full path of the executable and you should be fine.
NOTE3: Use your roor login for the entire set up

1. Open terminal and type "vncpasswd". It prompts for your password and also prompts for the password verification again. This ensures the password set up for the remote access for the current use.

2. Login as root using "su root"

3. Open the file /etc/sysconfig/vncservers. File can be opened in two ways:
a. "vi /etc/sysconfig/vncservers" OR
b. "gedit /etc/sysconfig/vncservers"

4. Look for the line that starts with # VNCSERVERS="1:myusername"
5. Uncomment the line (remove the #). This ensures the enabling of remote access to the user "myusername". If you want to enable more users for remote access, you can just have it something like "1:user1 2:user2 3:user3..."
6. save the file.
7. Now, you have to enable the VNC server on your machine using the command: "chkconfig vncserver on"
8. Start the VNC server using the command: "service vncserver start"
note: if the server is already running, you can restart using the command "server vncserver restart"
9. Now the set up is finished for the remote access. Make sure your firewall settings are in compliance to remote access.
Open Application => System Setting => Security level. and add "5901:tcp" to the other ports.
OR
Open system => administration => security and firewall and add "5901:tcp" to the other ports.

With this, installtion on LINUX machine is complted for enabling the remote access.

Set up to do in Windows machine:
1. Download VNC viewer at www.realvnc.com and install the same
2. Open vnc viewer, and it prompts for the server address:
enter ur server address the Server text box as "ipaddress:1" (xxx.xxx.xxx.xxx:1) here 1 is the number before username as shown in step4. You need to use the number that exists in that line of the vncservers file and click ok.
3. enter the password that you choose in step1.

With all this set up, You Are Ready to Access Your Redhat Linux machine from Windows machine.

After connecting to the redhat server, if the interface looks different, you just have to something more to get the real interface accessible through remote connection.
1. In your linux machine, open terminal and type "gedit /home/username/.vnc/xstartup"
2. uncomment (remove #) the two lines that starts with "unset" and "exec"
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
and save the file.
3. restart vncserver using the command "service vncserver restart" to apply changes
4. Now, reconnect using VNC viewer from windows machine and everything is ready to use on the Linux machine.

Saturday, August 15, 2009

ORM warnings: fail-safe cleanup messages

You often endup seeing the following warnings in the logs:
01:03:00,001 WARN [LoadContexts] fail-safe cleanup (collections) :
org.hibernate.engine.loading.CollectionLoadContext@103583b


OR

00:04:40,918 WARN [LoadContexts] fail-safe cleanup (collections) : org.hibernate.engine.loading.CollectionLoadContext@12f6fe9
<rs=com.ibm.db2.jcc.c.j@5a6c69>
These messages are expected and can simply ignore these warnings. These message related to the ORM technology you are using in the application and shows that how it cleanup up after itself avoid memory leaks.

Fix: You can even avoid these messages being displayed in the log by Upgrading your Hibernate jars to 3.x.x.

Difference between Set and List (Set vs List)

Set: an Interface available in "java.util" package.
  • a collection that cannot contain duplicate elements
  • generally order of the elements does not matter
  • models the mathematical set abstraction and is used to represent sets, such as the card comprising a poker hand
List: an Interface available in "java.util" package
  • a collection that can contain duplicate elements
  • it is an ordered collection, also called as a sequence
  • user of a List generally has control over where in (at what index) the List the user want to insert an element and access it using its index
When you access the Set using its Iterator, it doesn't guarantee the order of elements, whereas when you access the List using its Iterator, it gives you a sequential access to the elements in the list one by one.

For the better understanding, you can just execute the example program in my previous post "How Do I Convert Set into List".

Convert Calendar to Date

In one of the previous, date to calendar conversion was discussed. Following is the program to convert a Calendar (java.util.Calendar) object to Date (java.util.Date) object. The program can easily be understood by looking at the comments. You can even test drive the program directly.

Conversion from Calendar to Date is pretty easy:
1. given a calendar object, you just need to use the getTime() methos available in calendar class as the following:
Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
That's it.

package com.blog.javaexposure.util;

import java.util.Date;
import java.util.Calendar;

public class Calendar2Date {
public static void main(String[] rags){
//get the current date as Calendar object
Calendar cal = Calendar.getInstance();
// returns the date object represented by Calendar object
Date date = cal.getTime();
System.out.println("Current date using \n calendar object: "+cal);
System.out.println("date object: "+date);
// if you want to a get tomorrow's date and calendar object, do the following
cal.add(Calendar.DATE, 1);
date = cal.getTime();
System.out.println("Tomorrows date using \n calendar object: "+cal);
System.out.println("date object: "+date);
}
}

Note: Wheh you look at the calendar object value in the output, you see all properties of the calendar object.
È