Google Search

Sunday, May 29, 2016

Create JPEG Image Graph from CSV File

import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

import com.opencsv.CSVReader;

public class LineChart
{


   public static void main( String[ ] args ) throws Exception
   {
  DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset();
  String strFile = "F:\\Java\\Sample.csv";
  int  ColCount=getCols("F:\\Java\\Sample.csv");
 
  FileReader fr;
       fr = new FileReader("F:\\Java\\Sample.csv");
     
     
     
       String[] Headers = getHeaders("F:\\Java\\Sample.csv");
       System.out.println(Headers[0]);
 //Creation of DataSet Starts Here
       for (int k =0; k<ColCount;k++){
   

     CSVReader reader = new CSVReader(new FileReader(strFile));
   
     String [] nextLine;
     int lineNumber = 0;
     nextLine = reader.readNext();
   
   
 

     while ((nextLine = reader.readNext()) != null) {
       lineNumber++;
     
       line_chart_dataset.addValue( Double.parseDouble((nextLine[k])) , Headers[k] , "X" +lineNumber );
   

     }//End of While Loop
   
  }//End of For Loop - k
     
     
      // Chart Creation Starts here
      JFreeChart lineChartObject = ChartFactory.createLineChart(
         "Ececution Stats","Execution Number",
         "Value",
         line_chart_dataset,PlotOrientation.VERTICAL,
         true,true,false);

      int width = 1280; /* Width of the image */
      int height = 480; /* Height of the image */
      File lineChart = new File( "F:\\Java\\LineChart.jpeg" );
      ChartUtilities.saveChartAsJPEG(lineChart ,lineChartObject, width ,height);
   }
 
 
 
   public static int getCols(String xFileLocation) throws FileNotFoundException{

String InputLine = "";
int Rows = 0;
int Cols=0;
String[] InArray = null;

//String xFileLocation = "F:\\Java\\Sample.csv";
Scanner scanIn = new Scanner (new BufferedReader(new FileReader(xFileLocation)));
scanIn.useDelimiter(",");

while(scanIn.hasNextLine()){
InputLine = scanIn.nextLine();
InArray = InputLine.split(",");
Rows++;
Cols = InArray.length;

}

return Cols;
//System.out.println("Count of Rows is : " +Rows +" Count of Cols is "  + Cols);

}

public static int getRows(String xFileLocation) throws FileNotFoundException{

String InputLine = "";
int Rows = 0;
int Cols=0;
String[] InArray = null;

//String xFileLocation = "F:\\Java\\Sample.csv";
Scanner scanIn = new Scanner (new BufferedReader(new FileReader(xFileLocation)));
scanIn.useDelimiter(",");

while(scanIn.hasNextLine()){
InputLine = scanIn.nextLine();
InArray = InputLine.split(",");
Rows++;
Cols = InArray.length;

}

return Rows;
//System.out.println("Count of Rows is : " +Rows +" Count of Cols is "  + Cols);

}

public static String[] getHeaders(String xFileLocation) throws IOException{

FileReader fr;
    fr = new FileReader("F:\\Java\\Sample.csv");
   
   
    BufferedReader br = new BufferedReader(fr);
    String line = br.readLine();
    StringTokenizer st = new StringTokenizer(line, ",");
    String[] Headers = new String[getCols("F:\\Java\\Sample.csv")];
    int i = 0;
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset( );
    //String xLabel = st.nextToken();
   // System.out.println(xLabel);
    while(st.hasMoreTokens()){
    Headers[i] = st.nextToken();
 
   // System.out.println(Headers[i]);
    i=i+1;
    }

return Headers;


}

 
}

Tuesday, June 16, 2015

Triggers in Oracle 11g -> Execution Order in Oracle 11g

Before Oracle 11g, more than trigger can be created on one table but Oracle doesn't guarantee the order of execution of trigger.  Oracle has introduced the feature in Oracle 11g to execute the trigger in any order as per requirements.

Let’s look the example:

Monday, June 15, 2015

Virtual Column in Oracle

Oracle has introduced new feature in version 11 ie. Virtual column. Virtual column values are not stored on disk. They are generated at runtime using their associated expression.

Lets have a look how to create a table with Virtual Column 

CREATE TABLE testvirtual
(
   id1   NUMBER (10)
 , id2   NUMBER (10)
 , id3   NUMBER (10) GENERATED ALWAYS AS (id1 + id2) VIRTUAL
);
Virtual keyword is optional.

Sunday, June 14, 2015

Table Compression in Oracle 11g


Table compression was first introduced in Oracle 9i as a space saver feature only for data warehousing projects. In oracle 11g , this is acceptable as mainstream feature which is acceptable for OLTP Databases. This will result in saving storage space as this will compress the table, increased I/O performance and reduced memory use in the buffer cache. Definitely, this incurs CPU overhead because of compression.

Compression can be done at the tablespace, table or partition level . Options/Features which are available with Compression :

Wednesday, June 10, 2015

Regular Expression In Oracle

REGULAR EXPRESSION:
            A regular expression is a string or set of characters that describes the structure of some text .This expression helps to search a particular pattern on the line. It is composed of Literals and Metacharacters.