Hi All,
Create a phrase set and open it.
Select the "External" radio button and provide the URL to point to the wave file directory
for e.g.,
c://IVR/Phrases/Standard/
(or)
file:///opt/XXX/ (To point to the wave files location which is stored in MPP server)
(or)
http://hostname(or)IP address:port/IVR(application name)/Data/phrases/
Thursday, February 25, 2010
How to use DD Trace or logging in Java code
Hi All,
Here the code snippet to use the Trace functionality in POJOs or in Java code.
TraceInfo.trace(ITraceInfo.TRACE_LEVEL_DEBUG, ("Hai this is test trace for Debug mode"), objSCESession);
TraceInfo.trace(ITraceInfo.TRACE_LEVEL_INFO, ("Hai this is test trace for Info mode"), objSCESession);
To avoid System.out.println()s in DD projects Java code, use the Trace functionality.
Here the code snippet to use the Trace functionality in POJOs or in Java code.
TraceInfo.trace(ITraceInfo.TRACE_LEVEL_DEBUG, ("Hai this is test trace for Debug mode"), objSCESession);
TraceInfo.trace(ITraceInfo.TRACE_LEVEL_INFO, ("Hai this is test trace for Info mode"), objSCESession);
To avoid System.out.println()s in DD projects Java code, use the Trace functionality.
How to access DD project variables in Java code
Hi All,
Here the code snippet to access DD variables and manipulate the values of those variable in Java code.
If you have the simple variable in project variables list as "name" then here is the ways to get that variable value in Java code.
//First way
IVariable way1ToGet_Name = objSCESession.getVariable("name");
String strWay1ToGetName = way1ToGet_Name.getSimpleVariable().getStringValue();
//Second way
IVariable way2ToGet_Name = objSCESession.getVariable(IProjectVariables.NAME);
String strWay2ToGetName = way2ToGet_Name.getSimpleVariable().getStringValue();
//Third way
IVariableField way3ToGet_Name = objSCESession.getVariable(IProjectVariables.NAME).getSimpleVariable();
String getstrWay3ToGetNameName = way3ToGet_Name.getStringValue();
//Fourth way
String getstrWay4ToGetNameName = objSCESession.getVariableField("name").getStringValue();
//Fifth way
String getstrWay5ToGetNameName = objSCESession.getVariableField(IProjectVariables.NAME).getStringValue();
Note: Here there is a drawback of using the First and Fourth way, if we these ways then later in your project variables list if you change the variable name then it won't show any error and at runtime it will give you the problem.
So better go for other ways(other than First and Fourth). If you change the variable name in project variables list then it will show you some errors at compile time itself. So that you can figure out where exactly you have used that variable and where you need to change.
The above is to get the DD variable value in Java code and assign that value to local java variables.
If you want to set the DD variable value then you have to use setValue("") method.
The following line shows you how to set the String value to DD variable.
objSCESession.getVariableField(IProjectVariables.NAME).setValue("Ramu");
(or)
objSCESession.getVariableField(IProjectVariables.NAME).setValue(strName); //Java String type variable
IVariable mySimpleVar = objSCESession.getVariable(IProjectVariables.ARRAY_OF_PERSONS);
mySimpleVar.setCollection(new SimpleCollection(mySimpleVar.getSimpleVariable(), IProjectVariables.ARRAY_OF_PERSONS));
ICollection mySimpleCollectionVar = mySimpleVar.getCollection();
//To Clear the collection
mySimpleVar.getCollection().removeAll();
mySimpleCollectionVar.removeAll();
//To Reset the collection
mySimpleVar.getCollection().reset();
mySimpleCollectionVar.reset();
Here I have declared one complex variable called "person" with fields "age" and "name". To access these values use the following code snippet.
IComplexVariable complexVar = objSCESession.getVariable(IProjectVariables.PERSON).getComplexVariable();
IVariableField complexVarField1 = complexVar.getField(IProjectVariables.PERSON_FIELD_AGE);
IVariableField complexVarField2 = complexVar.getField(IProjectVariables.PERSON_FIELD_NAME);
complexVarField1.getIntValue();
complexVarField2.getStringValue();
To Set the values to complex fields use the following code snippet.
complexVarField1.setValue(28); //Set the age as 28
complexVarField2.setValue("Ramu"); //Set the name as Ramu
IComplexVariable complexVar = objSCESession.getVariable(IProjectVariables.PERSON).getComplexVariable();
IVariableField complexVarField1 = complexVar.getField(IProjectVariables.PERSON_FIELD_AGE);
IVariableField complexVarField2 = complexVar.getField(IProjectVariables.PERSON_FIELD_NAME);
complexVarField1.getIntValue();
complexVarField2.getStringValue();
complexVarField1.setValue(28); //Set the age as 28
complexVarField2.setValue("Ramu"); //Set the name as Ramu
IVariable myComplex = objSCESession.getVariable(IProjectVariables.PERSON);
myComplex.setCollection(new ComplexCollection(myComplex.getComplexVariable(), IProjectVariables.PERSON));
ICollection myComplexCollection = myComplex.getCollection();
//To Reset the complex collection
myComplexCollection.reset();
//To Remove the complex collection values and make it empty
myComplexCollection.removeAll();
IVariableField complexCollectionField1_Age = myComplex.getComplexVariable().getField(IProjectVariables.PERSON_FIELD_AGE);
IVariableField complexCollectionField2_Name = myComplex.getComplexVariable().getField(IProjectVariables.PERSON_FIELD_NAME);
//Set first record values
complexCollectionField1_Age.setValue(28);
complexCollectionField1_Age.setValue("Ramu");
myComplexCollection.append();
//Set Second record values
complexCollectionField1_Age.setValue(28);
complexCollectionField1_Age.setValue("Srikanth");
myComplex.getCollection().append();
//Reset the collection to travarse the collection values
myComplexCollection.reset();
while (myComplexCollection.hasMore())
{
myComplexCollection.next();
//Log the record values
TraceInfo.trace(ITraceInfo.TRACE_LEVEL_DEBUG, ("Person Age : " + complexCollectionField1_Age.getIntValue()), objSCESession);
TraceInfo.trace(ITraceInfo.TRACE_LEVEL_DEBUG, ("Person Name : " + complexCollectionField2_Name.getStringValue()), objSCESession);
}
//Reset the collection to travarse the collection values
myComplexCollection.reset();
Note: If you write your own POJO class then you need to pass SCESession object as parameter to the methods in POJO. Because, all the DD variables are stored in SCESession object.
Here the code snippet to access DD variables and manipulate the values of those variable in Java code.
1) Simple variables:
If you have the simple variable in project variables list as "name" then here is the ways to get that variable value in Java code.
//First way
IVariable way1ToGet_Name = objSCESession.getVariable("name");
String strWay1ToGetName = way1ToGet_Name.getSimpleVariable().getStringValue();
//Second way
IVariable way2ToGet_Name = objSCESession.getVariable(IProjectVariables.NAME);
String strWay2ToGetName = way2ToGet_Name.getSimpleVariable().getStringValue();
//Third way
IVariableField way3ToGet_Name = objSCESession.getVariable(IProjectVariables.NAME).getSimpleVariable();
String getstrWay3ToGetNameName = way3ToGet_Name.getStringValue();
//Fourth way
String getstrWay4ToGetNameName = objSCESession.getVariableField("name").getStringValue();
//Fifth way
String getstrWay5ToGetNameName = objSCESession.getVariableField(IProjectVariables.NAME).getStringValue();
Note: Here there is a drawback of using the First and Fourth way, if we these ways then later in your project variables list if you change the variable name then it won't show any error and at runtime it will give you the problem.
So better go for other ways(other than First and Fourth). If you change the variable name in project variables list then it will show you some errors at compile time itself. So that you can figure out where exactly you have used that variable and where you need to change.
The above is to get the DD variable value in Java code and assign that value to local java variables.
If you want to set the DD variable value then you have to use setValue("") method.
The following line shows you how to set the String value to DD variable.
objSCESession.getVariableField(IProjectVariables.NAME).setValue("Ramu");
(or)
objSCESession.getVariableField(IProjectVariables.NAME).setValue(strName); //Java String type variable
2) Simple Collection Variables:(To store Array of values to DD variable)
IVariable mySimpleVar = objSCESession.getVariable(IProjectVariables.ARRAY_OF_PERSONS);
mySimpleVar.setCollection(new SimpleCollection(mySimpleVar.getSimpleVariable(), IProjectVariables.ARRAY_OF_PERSONS));
ICollection mySimpleCollectionVar = mySimpleVar.getCollection();
//To Clear the collection
mySimpleVar.getCollection().removeAll();
mySimpleCollectionVar.removeAll();
//To Reset the collection
mySimpleVar.getCollection().reset();
mySimpleCollectionVar.reset();
3) Complex Variables:
Here I have declared one complex variable called "person" with fields "age" and "name". To access these values use the following code snippet.
IComplexVariable complexVar = objSCESession.getVariable(IProjectVariables.PERSON).getComplexVariable();
IVariableField complexVarField1 = complexVar.getField(IProjectVariables.PERSON_FIELD_AGE);
IVariableField complexVarField2 = complexVar.getField(IProjectVariables.PERSON_FIELD_NAME);
complexVarField1.getIntValue();
complexVarField2.getStringValue();
To Set the values to complex fields use the following code snippet.
complexVarField1.setValue(28); //Set the age as 28
complexVarField2.setValue("Ramu"); //Set the name as Ramu
4) Complex Collection variables:
IComplexVariable complexVar = objSCESession.getVariable(IProjectVariables.PERSON).getComplexVariable();
IVariableField complexVarField1 = complexVar.getField(IProjectVariables.PERSON_FIELD_AGE);
IVariableField complexVarField2 = complexVar.getField(IProjectVariables.PERSON_FIELD_NAME);
complexVarField1.getIntValue();
complexVarField2.getStringValue();
complexVarField1.setValue(28); //Set the age as 28
complexVarField2.setValue("Ramu"); //Set the name as Ramu
IVariable myComplex = objSCESession.getVariable(IProjectVariables.PERSON);
myComplex.setCollection(new ComplexCollection(myComplex.getComplexVariable(), IProjectVariables.PERSON));
ICollection myComplexCollection = myComplex.getCollection();
//To Reset the complex collection
myComplexCollection.reset();
//To Remove the complex collection values and make it empty
myComplexCollection.removeAll();
IVariableField complexCollectionField1_Age = myComplex.getComplexVariable().getField(IProjectVariables.PERSON_FIELD_AGE);
IVariableField complexCollectionField2_Name = myComplex.getComplexVariable().getField(IProjectVariables.PERSON_FIELD_NAME);
//Set first record values
complexCollectionField1_Age.setValue(28);
complexCollectionField1_Age.setValue("Ramu");
myComplexCollection.append();
//Set Second record values
complexCollectionField1_Age.setValue(28);
complexCollectionField1_Age.setValue("Srikanth");
myComplex.getCollection().append();
//Reset the collection to travarse the collection values
myComplexCollection.reset();
while (myComplexCollection.hasMore())
{
myComplexCollection.next();
//Log the record values
TraceInfo.trace(ITraceInfo.TRACE_LEVEL_DEBUG, ("Person Age : " + complexCollectionField1_Age.getIntValue()), objSCESession);
TraceInfo.trace(ITraceInfo.TRACE_LEVEL_DEBUG, ("Person Name : " + complexCollectionField2_Name.getStringValue()), objSCESession);
}
//Reset the collection to travarse the collection values
myComplexCollection.reset();
Note: If you write your own POJO class then you need to pass SCESession object as parameter to the methods in POJO. Because, all the DD variables are stored in SCESession object.
Friday, June 26, 2009
Settings to write the vxml code though eclipse...
Hi All,
If you need editor for vxml then do the following.
Take DTD for the vxml version(we can get it from W3C site) and configure your eclipse and add *.vxml extension to file assoication in eclipse properties.
example :
in Eclipse
Window -> preference - > General -> Editor -> File Assoication (add *.vxml extension and choose xml editor)
DTD configuration for eclipse
in Eclipse
Window -> preference - > General ->Web and XML -> XML Catalog
Press Add button
specify location of the dtd file (ex: /home/ramu/xxxxx.dtd)
Key Type is Public ID
Key is specify some common name (because this name only you specify DOCTYPE in your vxml file). example ://DTD/vxml
and specify alternative url (ex:https://studio.tellme.com/vxml2/dtd/vxml-20-tm-pub.dtd) and press ok
it will create entry for user specified entries. in XML Catalog window
then create vxml file
example
<?xml version = "1.0"?>
<!DOCTYPE vxml PUBLIC "//DTD/vxml" "unknown.dtd">
<vxml version="2.0">
</vxml>
<vxml version="2.0">
</vxml>
//DTD/vxml is your key
I hope this will help you.
If you need editor for vxml then do the following.
Take DTD for the vxml version(we can get it from W3C site) and configure your eclipse and add *.vxml extension to file assoication in eclipse properties.
example :
in Eclipse
Window -> preference - > General -> Editor -> File Assoication (add *.vxml extension and choose xml editor)
DTD configuration for eclipse
in Eclipse
Window -> preference - > General ->Web and XML -> XML Catalog
Press Add button
specify location of the dtd file (ex: /home/ramu/xxxxx.dtd)
Key Type is Public ID
Key is specify some common name (because this name only you specify DOCTYPE in your vxml file). example ://DTD/vxml
and specify alternative url (ex:https://studio.tellme.com/
it will create entry for user specified entries. in XML Catalog window
then create vxml file
example
<?xml version = "1.0"?>
<!DOCTYPE vxml PUBLIC "//DTD/vxml" "unknown.dtd">
<vxml version="2.0">
</vxml>
<vxml version="2.0">
</vxml>
//DTD/vxml is your key
I hope this will help you.
--
Thanks,
Srikanth Reddy
Creating the DD variables at runtime through java code in DD(Dialog Designer)
Hi All,
The Following code will help you to create the variables at runtime through java code in Avaya Dialog Designer and we can use those variables throughout the session.
Sample Code snippet:
String varName = "CreatedVar";
String varValue = "123456";
//Creating the Simple Variable
IVariable ddMySampleVar = SimpleVariable.createSimpleVariable(varName, varValue, null, mySession, false, false);
//Adding the Simple Variable to DD session(SCESession)
mySession.putVariable(ddMySampleVar);
// Log the created variable value through app traces
if (mySession.isAppTraceEnabled())
{
TraceInfo.trace(ITraceInfo.TRACE_LEVEL_DEBUG, ("My Sample Variable value is : " + ddMySampleVar.getStringValue()), mySession);
}
The Following code will help you to create the variables at runtime through java code in Avaya Dialog Designer and we can use those variables throughout the session.
Sample Code snippet:
String varName = "CreatedVar";
String varValue = "123456";
//Creating the Simple Variable
IVariable ddMySampleVar = SimpleVariable.createSimpleVariable(varName, varValue, null, mySession, false, false);
//Adding the Simple Variable to DD session(SCESession)
mySession.putVariable(ddMySampleVar);
// Log the created variable value through app traces
if (mySession.isAppTraceEnabled())
{
TraceInfo.trace(ITraceInfo.TRACE_LEVEL_DEBUG, ("My Sample Variable value is : " + ddMySampleVar.getStringValue()), mySession);
}
Below is the API declaration of createSimpleVariable method:
public static IVariable createSimpleVariable(java.lang.String name,
java.lang.String value,
java.lang.String factoryID,
SCESession session,
boolean isCollection,
boolean transparencyAllowed)
Thanks,
Ramu.
java.lang.String value,
java.lang.String factoryID,
SCESession session,
boolean isCollection,
boolean transparencyAllowed)
Thanks,
Ramu.
Tuesday, June 9, 2009
Getting the Array of Objects from Oracle stored procedure through Java code
Hi All,
I had a requirement, like, get Array of Objects from Oracle stored procedure by using Java (JDBC) code. Means, my Oracle stored procedure will return Array type of output variable. That array type will hold the Objects(which is user defined objects).This Array type of variable need to get it by JDBC code. So for this I did the coding in the following manner.
I guess this may be helpful to the guys who is having the same type of requirement( get the Array of Objects or only Object from the DataBase).
From DB side :-
1. I have crated the Object(person) as follows:
create or replace type OBJ_PERSON_INFO as object (
p_name varchar2(30),
p_age number,
p_mobile_no number
)
2. I have created the Array of Object variable as follows:
create or replace TYPE ARR_PERSON_INFO AS VARRAY(50) OF OBJ_PERSON_INFO;
3. I have created the stored procedure as follows(with hard coded values):
create or replace procedure get_persons_info
(
i_area_code in varchar2, /* input parameter */
o_arr_persons out arr_person_info, /* output parameters */
o_status_code out varchar2,
o_status_msg out varchar2
) AS
ProcedureName varchar2(30) := 'get_persons_info';
begin
/**************************************** Main Function ***********************************************/
o_arr_persons := arr_person_info(obj_person_info('Ramu',25,9916379951),obj_person_info('Siva',26,9247469543),obj_person_info('Saran',30,99868583));
o_status_code := '0'; -- Success
o_status_msg := 'Success';
/**************************************** Error Handler ***********************************************/
exception
when others then
o_status_code := '-100';
o_status_msg := sqlcode || substr (sqlerrm, 1, 500) || ' in the SP:' || ProcedureName;
end get_persons_info;
/* End of stored procedure */
The above stored procedure will return 3 output paramertes. Those are :
1. Array Of Person Objects
2. Status Code
and 3. Status Message.
Here, the "o_arr_persons" object will hold the 3 persons details(We hard coded with 3 records).
From Java (JDBC) side :
I have created a java class to get the details of persons from the Oracle DB by using JDBC (Callable statement).
The code of this calss is :
//Code starts here
package com.ramu.dbutil.services;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
/**
* @author : Ramu.Polamreddy
* Created Date : 08/JUN/2009
* Modified Date :
* Modified By :
* Description : Get the array of person details from Oracle DB stored procedure
* and display those records on the console.
*/
public class GetPersonDetails {
//Variable declarations
private Connection connection = null;
private CallableStatement callableStatement = null;
private ResultSet resultSet = null;
//End of variable declarations
//Return the Connection object
public Connection getConnection()throws ClassNotFoundException, SQLException, Exception
{
System.out.println("Entered into GetPersonDetails.getConnection method");
//DB Properties
String driverName = "oracle.jdbc.OracleDriver"; //Driver name
String url = "jdbc:oracle:thin:@127.0.0.1:1521:xe"; //JDBC URL
String username = "person"; //User Name
String password = "person"; //Password
//Load the JDBC driver and get connection
Class.forName(driverName);
connection = DriverManager.getConnection(url, username, password);
System.out.println("Returning the Connection object from GetPersonDetails.getConnection method");
return connection;
}
public void getArrPersonObjects() {
System.out.println("Entered into GetPersonDetails.getArrPersonObjects method");
try
{
//Getting Connection object
connection = getConnection() ;
//Get Docket number from Back end
callableStatement = connection.prepareCall("call get_persons_info(?,?,?,?)");
//Set Input parameters
callableStatement.setString (1, "NLR1"); //I_AREA_CODE
System.out.println("Input param is registered...");
//Register output parameters
callableStatement.registerOutParameter (2, Types.ARRAY, "ARR_PERSON_INFO"/* Name of the OBJECT/ARRAY, Which we have created at Oracle DB */); //O_ARR_PERSONS
System.out.println("Output param ARRAY is registered...");
callableStatement.registerOutParameter (3, Types.VARCHAR); //O_STATUS_CODE
callableStatement.registerOutParameter (4, Types.VARCHAR); //O_STATUS_MSG
System.out.println("Output params are registered...");
// Call the stored procedure
callableStatement.executeUpdate();
System.out.println("executeUpdate() is done");
/*
//Suppose in case if we want to get only one object
//i.e., If Our stored procedure is returning only Object type
//(Person and we need to mention the name of the Object while
//registering the parameter, like above)[not Array of objects]
//then the following code will help to get that
oracle.sql.STRUCT person = (oracle.sql.STRUCT) callableStatement.getObject(1);
Object[] personValues = person.getAttributes();
String pName = (String) personValues[0];
String pAge = (String) personValues[1];
String pMbNo = (String) personValues[2];
*/
System.out.println("******************************");
// Get the output parameter values
oracle.sql.ARRAY objArray = (oracle.sql.ARRAY) callableStatement.getObject(2);
System.out.println("oracle.sql.ARRAY created");
resultSet = objArray.getResultSet();
System.out.println("Got the Result set object from oracle.sql.ARRAY");
if (resultSet != null && resultSet.getFetchSize() > 0)
{
System.out.println("ResultSet is not empty");
System.out.println("Got the size of the resultSet as : " + resultSet.getFetchSize());
}
else
{
System.out.println("ResultSet is empty");
}
while (resultSet.next())
{
//Display the record number on console
System.out.println("Got Record : " + resultSet.getRow() + " from result set");
// The first column contains the element index and the
// second column contains the element value
System.out.println(">> index " + resultSet.getInt(1)+" = " + resultSet.getObject(2));
//We can get the Oracle Object type data by oracle.sql.STRUCT object
oracle.sql.STRUCT myStruct = (oracle.sql.STRUCT) resultSet.getObject(2);
//Getting the attributes/properties of Oracle Object type as array of java Objects
Object[] personInfo = myStruct.getAttributes();
//Display all the details on the console
System.out.println("-----------------");
System.out.println("Person Name : " + personInfo[0]);
System.out.println("Person Age : " + personInfo[1]);
System.out.println("Mobile Number : " + personInfo[2]);
System.out.println("------------------");
}
System.out.println("********************************");
//Get and log the DB Stored Procedure returned status values
String statusCode = callableStatement.getString(3);
String statusMsg = callableStatement.getString(4);
System.out.println("Got the DB stored procedure Status details as...");
System.out.println("Status Code : " + statusCode);
System.out.println("Status Msg : " + statusMsg);
}
catch (Exception exception) {
System.err.println("Got Exception as : " + exception.getMessage());
exception.printStackTrace();
}
finally
{
try
{
if (resultSet != null)
{
resultSet.close();
System.out.println("Result Set is closed");
}
if (callableStatement != null)
{
callableStatement.close();
System.out.println("Callable Statement is closed");
}
if (connection != null)
{
connection.close();
System.out.println("Connection closed");
}
}
catch (Exception exception) {
System.err.println("Got Exception : " + exception.getMessage());
}
}
System.out.println("Exiting from GetPersonDetails.getArrPersonObjects() method");
}
public static void main(String[] args) {
System.out.println("Testing this Sample code");
System.out.println("Calling the GetPersonDetails.getArrPersonObjects() method");
GetPersonDetails getPersonDetails = new GetPersonDetails();
getPersonDetails.getArrPersonObjects();
System.out.println("Done");
}
}
//End of the java code
Thanks and Regards,
Ramu.
I had a requirement, like, get Array of Objects from Oracle stored procedure by using Java (JDBC) code. Means, my Oracle stored procedure will return Array type of output variable. That array type will hold the Objects(which is user defined objects).This Array type of variable need to get it by JDBC code. So for this I did the coding in the following manner.
I guess this may be helpful to the guys who is having the same type of requirement( get the Array of Objects or only Object from the DataBase).
From DB side :-
1. I have crated the Object(person) as follows:
create or replace type OBJ_PERSON_INFO as object (
p_name varchar2(30),
p_age number,
p_mobile_no number
)
2. I have created the Array of Object variable as follows:
create or replace TYPE ARR_PERSON_INFO AS VARRAY(50) OF OBJ_PERSON_INFO;
3. I have created the stored procedure as follows(with hard coded values):
create or replace procedure get_persons_info
(
i_area_code in varchar2, /* input parameter */
o_arr_persons out arr_person_info, /* output parameters */
o_status_code out varchar2,
o_status_msg out varchar2
) AS
ProcedureName varchar2(30) := 'get_persons_info';
begin
/**************************************** Main Function ***********************************************/
o_arr_persons := arr_person_info(obj_person_info('Ramu',25,9916379951),obj_person_info('Siva',26,9247469543),obj_person_info('Saran',30,99868583));
o_status_code := '0'; -- Success
o_status_msg := 'Success';
/**************************************** Error Handler ***********************************************/
exception
when others then
o_status_code := '-100';
o_status_msg := sqlcode || substr (sqlerrm, 1, 500) || ' in the SP:' || ProcedureName;
end get_persons_info;
/* End of stored procedure */
The above stored procedure will return 3 output paramertes. Those are :
1. Array Of Person Objects
2. Status Code
and 3. Status Message.
Here, the "o_arr_persons" object will hold the 3 persons details(We hard coded with 3 records).
From Java (JDBC) side :
I have created a java class to get the details of persons from the Oracle DB by using JDBC (Callable statement).
The code of this calss is :
//Code starts here
package com.ramu.dbutil.services;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
/**
* @author : Ramu.Polamreddy
* Created Date : 08/JUN/2009
* Modified Date :
* Modified By :
* Description : Get the array of person details from Oracle DB stored procedure
* and display those records on the console.
*/
public class GetPersonDetails {
//Variable declarations
private Connection connection = null;
private CallableStatement callableStatement = null;
private ResultSet resultSet = null;
//End of variable declarations
//Return the Connection object
public Connection getConnection()throws ClassNotFoundException, SQLException, Exception
{
System.out.println("Entered into GetPersonDetails.getConnection method");
//DB Properties
String driverName = "oracle.jdbc.OracleDriver"; //Driver name
String url = "jdbc:oracle:thin:@127.0.0.1:1521:xe"; //JDBC URL
String username = "person"; //User Name
String password = "person"; //Password
//Load the JDBC driver and get connection
Class.forName(driverName);
connection = DriverManager.getConnection(url, username, password);
System.out.println("Returning the Connection object from GetPersonDetails.getConnection method");
return connection;
}
public void getArrPersonObjects() {
System.out.println("Entered into GetPersonDetails.getArrPersonObjects method");
try
{
//Getting Connection object
connection = getConnection() ;
//Get Docket number from Back end
callableStatement = connection.prepareCall("call get_persons_info(?,?,?,?)");
//Set Input parameters
callableStatement.setString (1, "NLR1"); //I_AREA_CODE
System.out.println("Input param is registered...");
//Register output parameters
callableStatement.registerOutParameter (2, Types.ARRAY, "ARR_PERSON_INFO"/* Name of the OBJECT/ARRAY, Which we have created at Oracle DB */); //O_ARR_PERSONS
System.out.println("Output param ARRAY is registered...");
callableStatement.registerOutParameter (3, Types.VARCHAR); //O_STATUS_CODE
callableStatement.registerOutParameter (4, Types.VARCHAR); //O_STATUS_MSG
System.out.println("Output params are registered...");
// Call the stored procedure
callableStatement.executeUpdate();
System.out.println("executeUpdate() is done");
/*
//Suppose in case if we want to get only one object
//i.e., If Our stored procedure is returning only Object type
//(Person and we need to mention the name of the Object while
//registering the parameter, like above)[not Array of objects]
//then the following code will help to get that
oracle.sql.STRUCT person = (oracle.sql.STRUCT) callableStatement.getObject(1);
Object[] personValues = person.getAttributes();
String pName = (String) personValues[0];
String pAge = (String) personValues[1];
String pMbNo = (String) personValues[2];
*/
System.out.println("******************************");
// Get the output parameter values
oracle.sql.ARRAY objArray = (oracle.sql.ARRAY) callableStatement.getObject(2);
System.out.println("oracle.sql.ARRAY created");
resultSet = objArray.getResultSet();
System.out.println("Got the Result set object from oracle.sql.ARRAY");
if (resultSet != null && resultSet.getFetchSize() > 0)
{
System.out.println("ResultSet is not empty");
System.out.println("Got the size of the resultSet as : " + resultSet.getFetchSize());
}
else
{
System.out.println("ResultSet is empty");
}
while (resultSet.next())
{
//Display the record number on console
System.out.println("Got Record : " + resultSet.getRow() + " from result set");
// The first column contains the element index and the
// second column contains the element value
System.out.println(">> index " + resultSet.getInt(1)+" = " + resultSet.getObject(2));
//We can get the Oracle Object type data by oracle.sql.STRUCT object
oracle.sql.STRUCT myStruct = (oracle.sql.STRUCT) resultSet.getObject(2);
//Getting the attributes/properties of Oracle Object type as array of java Objects
Object[] personInfo = myStruct.getAttributes();
//Display all the details on the console
System.out.println("-----------------");
System.out.println("Person Name : " + personInfo[0]);
System.out.println("Person Age : " + personInfo[1]);
System.out.println("Mobile Number : " + personInfo[2]);
System.out.println("------------------");
}
System.out.println("********************************");
//Get and log the DB Stored Procedure returned status values
String statusCode = callableStatement.getString(3);
String statusMsg = callableStatement.getString(4);
System.out.println("Got the DB stored procedure Status details as...");
System.out.println("Status Code : " + statusCode);
System.out.println("Status Msg : " + statusMsg);
}
catch (Exception exception) {
System.err.println("Got Exception as : " + exception.getMessage());
exception.printStackTrace();
}
finally
{
try
{
if (resultSet != null)
{
resultSet.close();
System.out.println("Result Set is closed");
}
if (callableStatement != null)
{
callableStatement.close();
System.out.println("Callable Statement is closed");
}
if (connection != null)
{
connection.close();
System.out.println("Connection closed");
}
}
catch (Exception exception) {
System.err.println("Got Exception : " + exception.getMessage());
}
}
System.out.println("Exiting from GetPersonDetails.getArrPersonObjects() method");
}
public static void main(String[] args) {
System.out.println("Testing this Sample code");
System.out.println("Calling the GetPersonDetails.getArrPersonObjects() method");
GetPersonDetails getPersonDetails = new GetPersonDetails();
getPersonDetails.getArrPersonObjects();
System.out.println("Done");
}
}
//End of the java code
Thanks and Regards,
Ramu.
Sunday, May 3, 2009
Welcome note
Hi Friends,
This is Ramu, a Software Professional working on Java, VoiceXML and IVR application Development. This blog is to share knowledge on Java, VoiceXML, and IVR application development.
This is Ramu, a Software Professional working on Java, VoiceXML and IVR application Development. This blog is to share knowledge on Java, VoiceXML, and IVR application development.
Subscribe to:
Posts (Atom)