The problem.
From CVP need to retrieve data from an Oracle database. Some data is available through stored procedures.
Call Studio Database Element works with simple SELECT statements, but it doesn't have the ability to execute stored procedures and retrieve the data cursors. SELECT * FROM <stored_proc> is not possible
I am considering attacking the problem through an Action Element with a custom Java class. To keep things consistent I would like to be able to pull the db connection info from the Tomcat JNDI configuration, rather than defining the db conn parameters inside the custom class.
Any insights? Somebody with similar problems that already have a solution?
I'm not a real big fan of the Call Studio Database Elementor or the Tomcat JNDI. I think the best method is to create a custom decision element and not utilize the JNDI. I did this with MySQL is it is far easier than messing with the out of the box element. I'm still working cleaning the code up but below is a hacked version of what I am doing.
import java.util.ArrayList;
import java.sql.*;
import com.audium.server.AudiumException;
import com.audium.server.session.DecisionElementData;
import com.audium.server.voiceElement.*;
public class ghtsCountyCheck extends DecisionElementBase implements ElementInterface {
public ghtsCountyCheck(){
}
public String getElementName(){
return "mysqlDummy";
}
public String getDisplayFolderName(){
return "Custom Elements";
}
public String getDescription(){
return "Check entry prior to building menu";
}
public Setting[] getSettings() throws ElementException {
return null;
}
public ExitState[] getExitStates() throws ElementException {
ExitState exitStateArray[] = new ExitState[4];
exitStateArray[0] = new ExitState("match", "match", "");
exitStateArray[1] = new ExitState("select", "select", "");
exitStateArray[2] = new ExitState("notFound", "notFound", "");
exitStateArray[3] = new ExitState("error", "error", "");
return exitStateArray;
}
public ElementData[] getElementData() throws ElementException {
ElementData elementDataArray[] = new ElementData[1];
elementDataArray[0] = new ElementData("NULL", "NULL");
return elementDataArray;
}
public String doDecision(String name, DecisionElementData decisionData) throws ElementException {
Connection conn = null;
ResultSet rs;
int _rowcount = 0;
ArrayList _resultset = new ArrayList();
try {
String sLastEntry = (String)decisionData.getSessionData("lastEntry");
decisionData.setSessionData("_rowcount", Integer.toString(_rowcount));
decisionData.setSessionData("_resultset", _resultset);
try {
String userName = "XXXXXXX";
String password = "XXXXXX";
String url = "jdbc:mysql://XXXXXXXX.com";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
Statement s = conn.createStatement ();
s.executeQuery ("SELECT distinct * FROM dbxxxx.XXXXXX where substring(XXXX,1,4)='"+sLastEntry+"' LIMIT 9;");
rs = s.getResultSet ();
while (rs.next ()) {
_resultset.add(rs.getString("COUNTYNAME").toLowerCase());
++_rowcount;
}
rs.close ();
s.close ();
}
catch (Exception e) {
System.err.println ("Cannot connect to database server\n");
System.err.println(e);
try {
String userName = "XXXXXXX";
String password = "XXXXXXX";
String url = "jdbc:mysql://YYYYYYYYY.com";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
Statement s = conn.createStatement ();
s.executeQuery ("SELECT distinct * FROM dbYYYY.XXXXX where substring(XXXXXX,1,4)='"+sLastEntry+"' LIMIT 9;");
rs = s.getResultSet ();
while (rs.next ()) {
_resultset.add(rs.getString ("FIELD"));
++_rowcount;
}
rs.close ();
s.close ();
}
catch (Exception ex) {
System.err.println ("Cannot connect to database server\n");
System.err.println(ex);
}
}
finally {
if (conn != null) {
try {
conn.close ();
if (_rowcount == 1) {
return "match";
} else if (_rowcount > 0) {
decisionData.setSessionData("_rowcount", Integer.toString(_rowcount));
decisionData.setSessionData("_resultset", _resultset);
return "select";
} else {
return "notfound";
}
}
catch (Exception e) { /* ignore close errors */ }
} else {
return "error";
}
}
}
catch(RuntimeException e){
e.printStackTrace();
}
catch(AudiumException e){
e.printStackTrace();
}
return "error";
}