Saturday, June 4, 2011

How to do DB2 administration when Instance ID is locked

How to do DB2 administration when the instance id is locked or sudo is revoked.
  1. Login to the server with your personal id (id should be a member of db2admin group)
  2. Find the instance home directory using lsuser command or finger command.
  3. Switch to the instance home directory.
  4. Now go to sqllib directory and execute db2profile. This will setup the environment for particular instance.
  5. Now attach to the instance using the following command.
  6. Now we can perform almost all the administration tasks, with out instance id. (Only thing is our id should be part of db2admin group).
  7. Certain specific utility like db2pd, db2top may not work due to restrictions, but still we are good to go with other normal DBA activity.
In this way we can perform all the administration tasks, even instance id is locked or sudo is not working.

Tuesday, May 12, 2009

Retriving Excel Data using Jakarta POI API in Java

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import java.io.*;
import java.util.*;
import java.sql.*;
public class POIExcelReader
{
/** Creates a new instance of POIExcelReader */
public POIExcelReader ()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "scott", "tiger");
Statement stmt=con.createStatement();
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**
* This method is used to display the Excel content to command line.
* @param xlsPath
*/
@SuppressWarnings ("unchecked")
public void displayFromExcel (String xlsPath)
{
InputStream inputStream = null;
try
{
inputStream = new FileInputStream (xlsPath);
}
catch (FileNotFoundException e)
{
System.out.println ("File not found in the specified path.");
e.printStackTrace ();
}
POIFSFileSystem fileSystem = null;
try
{
fileSystem = new POIFSFileSystem (inputStream);
HSSFWorkbook workBook = new HSSFWorkbook (fileSystem);
HSSFSheet sheet = workBook.getSheetAt (0);
Iterator rows = sheet.rowIterator ();
while (rows.hasNext ())
{
HSSFRow row = rows.next ();
// once get a row its time to iterate through cells.
Iterator cells = row.cellIterator ();
while (cells.hasNext ())
{
HSSFCell cell = cells.next ();
// Now we will get the cell type and display the values accordingly.
System.out.println();
switch (cell.getCellType ())
{
case HSSFCell.CELL_TYPE_NUMERIC :
{
// cell type numeric.
System.out.print (cell.getNumericCellValue ()+"\t");
break;
}
case HSSFCell.CELL_TYPE_STRING :
{
// cell type string.
HSSFRichTextString richTextString = cell.getRichStringCellValue();
System.out.print (richTextString.getString()+"\t");
break;
}
default :
{
// types other than String and Numeric.
System.out.println ("Type not supported.");
break;
}
}
System.out.println();
}
}
}
catch(IOException e)
{
e.printStackTrace ();
}
}
public static void main (String[] args)
{
POIExcelReader poiExample = new POIExcelReader ();
String xlsPath = "e:/data.xls";
poiExample.displayFromExcel(xlsPath);
}
}