February 27, 2013

Creating object to inner class in Java

I have a class definition like below and I want to create an object for the inner class.

class outerclass
    public class innerclass{

To create an object for the above innerclass, we should follow the below syntax.

outerclass.innerclass obj=new outerclass().new innerclass();

February 6, 2013

Data Source connection to AppModule

By default AppModule is configured to database through the connection created in JDeveloper. But if we want to change the connection type to “JDBC DataSource” from “JDBC URL”, it expects a Datasource name as an input. But we need to pass the JNDI name to this field instead of data source name.

How to display a message dialog on the JSF page

The below code will be used to display a message dialog on the JSF page.

        FacesContext facesContext = FacesContext.getCurrentInstance();
        FacesMessage facesMessage = new FacesMessage(message);
        facesContext.addMessage(null, facesMessage);

Where message is the message what we want to display on the dialog box and severity is to show the severity of the message. Example for severity is FacesMessage.SEVERITY_INFO which displays the dialog box as an information message. Inputs for severity is available in FacesMessage class.

Creating GraphDataModel object for pieGraph

When creating a dvt:pieGraph, an object of GraphDataModel class needs to be passed as input to it.

The below code helps to understand how to create GraphDataModel object.

In the below code, I am taking data from database.

    public static GraphDataModel getGraphDataModel(String table,                                                                                                     String cust_id) throws Exception {     
  String[] columnLabels = { "" };
        String[] columnNames = getColumnNames(table);//User defind Method, returns all column names of the given table
        int size = columnNames.length;
        if (ignoreFields != null)
            size = size - ignoreFields.size();
        Object[][] data2 = new Object[1][size];
        String[] seriesLabels = new String[size];

        Connection con = createConnection(); //Method to return connection object
        Statement stmt = con.createStatement();
                StringBuilder query = new StringBuilder("SELECT * FROM " + table+ "where cust_id="+cust_id);
        System.out.println("Query of graph: " + query);
        ResultSet rs = stmt.executeQuery(query);
        if (rs.next()) {
            for (int i = 0, j = 0; i < columnNames.length && j < size; i++) {
                if ("cust_id".equals(columnNames[i]))
                seriesLabels[j] = columnNames[i];
                data2[0][j] = new Double(rs.getDouble(i + 1));

        oracle.dss.dataView.LocalXMLDataSource ds =
            new oracle.dss.dataView.LocalXMLDataSource(columnLabels,
                                                       seriesLabels, data2);
        GraphDataModel graphData =
            new oracle.adf.view.faces.bi.model.GraphDataModel();
        return graphData;}

Inserting Date and Time in database

I want to insert date and time into a field of a Oracle table whose data type is "Date".

To do so, I have used the below command.

to_date('2011/12/12 11:15:00', 'yyyy/mm/dd hh24:mi:ss')


Table definition: 
create table ATG(local_id varchar2(50) primary key,Last_Sale Date, Last_Sale_Value varchar2(50),Total_12_month_Value  varchar2(50));

In the above table, I want to insert data and time to "Last_Sale field".

Insert data:

insert into ATG values ('9986',to_date('2011/12/12 11:15:00', 'yyyy/mm/dd hh24:mi:ss'),'£319.99','£1,234,96');