Friday, May 31, 2013

Date Conversions using XMLGregorianCalendar in Java

How to convert to different date data types using XMLGregorianCalendar in Java


/**
   * Returns XMLGregorianCalendar for Current Date and Time.
   */
  public XMLGregorianCalendar getCurrentDateTimeAsXMLGregorianCalendar()
  {
    GregorianCalendar gc = new GregorianCalendar();
    return new XMLGregorianCalendarImpl(gc);
  }

  /**
   * Convert supplied XMLGregorianCalendar to java util Date
   */
  public Date getJavaDateFromXMLGregorianCal(XMLGregorianCalendar pXCal)
  {
    if (pXCal != null)
    {
      return pXCal.toGregorianCalendar().getTime();
    }
    return null;
  }
   // Convert java.util.Date to XMLGregorianCalendar
  public XMLGregorianCalendar toXMLGregorianCalendar(Date pDate)
  {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(pDate.getTime());
    return new XMLGregorianCalendarImpl(gc);
  }

Tuesday, May 28, 2013

How to retrieve data from Oracle Database using JSP

How to connect to Oracle Database in JSP ? How to query & Retrieve data from Database in JSP

- Below is the snippet about connecting to Oracle Database in JSP



Below is the snapshot to retrieve data from Result set and display it on to the screen using JSTL tab libraries in JSP


Thursday, May 23, 2013

How to Write JUnit Tests using Jdeveloper

JUnit is a simple, open source framework to write and run repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks. JUnit features include:
- Assertions for testing expected results
- Test fixtures for sharing common test data
- Test runners for running tests
File -> New -> Choose TestSuite as shown below




- Create a Test class as shown below


- Write the test methods as shown below, Ensure to have @Test annotation.
- Ensure to import below packages
                      import static org.junit.Assert.*;
                      import org.junit.Test;


- Open the test suite class, Structure Window -> Right click on class name -> Choose Run/Debug option



- Once you run all the tests, below is the screenshot how it looks like the results.

For More Info, visit : http://junit.sourceforge.net/doc/faq/faq.htm#running_15

Tuesday, May 7, 2013

Remote Desktop Share using Google Chrome browser

Google chrome has one of the best feature, I use frequently. i.e Remote Desktop Sharing. Very simple to access remote desktop.


Step1 : Open the below url in Google Chrome browser

https://chrome.google.com/webstore/detail/chrome-remote-desktop/gbchcmhmhahfdphkhkmpfmihenigjmpp/related

Step2 :  Click on 'Launch App' button

Step 3:  If you want to access remote machine, then click on 'Access' , Get the access code from other end , enter the access code when prompted, you are all set to access the remote machine.

Step4 : If someone want to access your machine, then click on 'Share' , Provide the generated access code to other end, The should able to access your machine.


Wednesday, May 1, 2013

How to convert Array to List and List to Array

Use case : How to convert java.util.List to Array & Array to java.util.List in Java

Implementation : 

List to Array conversion

List<String> nameList = new ArrayList<String>();
nameList.add("Steve");
nameList.add("Tom");

// Convert List to Array with Generics.
String[] nameArray = nameList.toArray(new String[nameList.size()]);

Array to List conversion

// Convert Arrays to List with Generics
List<String> lastNameList = new ArrayList<String>(Arrays.asList(nameArr));