This document was generated from CDN thread
Created by: Doan Khanh Tan Thanh on 16-06-2009 03:32:05 AM
Dear friends,
I try to create a class extends to Action element. But when I do deploy, it return no result.
I want this class receive Calling Number and do the query to database (SQL as I test, later if it works I will do for another database). After query I will get Name, Address, Email of this Customer based on Calling Number (ANI).
Please help to take a look on my program and help me to fix it.
Thank you very much.
import com.audium.server.AudiumException;
import com.audium.server.voiceElement.ActionElementBase;
import com.audium.server.session.ActionElementData;
import java.sql.*;
/**
* This class is called when a standard action has been configured to use a
* Java class. Since this is a standard action element, it applies to a
* specific application and does not have a configuration. As a result, the
* only method needed in this class is the doAction method.
*/
public class DBLookupStandardAction extends ActionElementBase
{
class WhatIGot
{
String ANI = null;
String Name = null;
String Address = null;
String Email = null;
}
public void doAction(String name, ActionElementData data) throws AudiumException
{
Connection conn = null;
String Name = null;
String Address = null;
conn = connectToDatabase();
String ani = data.getAni();
WhatIGot whatigot = new WhatIGot();
whatigot = QueryDatabase(conn, ani);
Name = whatigot.Name;
Address = whatigot.Address;
data.setSessionData("Name",Name);
data.setSessionData("Address",Address);
// PUT YOUR CODE HERE.
}
private Connection connectToDatabase()
{
Connection conn = null;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:sqlserver://172.16.3.5:1433;DatabaseName=hcmpt","sa","");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
System.exit(1);
}
catch (SQLException e)
{
e.printStackTrace();
System.exit(2);
}
return conn;
}
/*Query*/
private WhatIGot QueryDatabase(Connection conn, String ANI)
{
WhatIGot WhatIGot = new WhatIGot();
try
{
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT prefixnos, Name, Address, Email FROM customer_info where prefixnos = ANI");
WhatIGot.ANI = rs.getString ("prefixnos");
WhatIGot.Name = rs.getString ("Name");
WhatIGot.Address = rs.getString ("Address");
WhatIGot.Email = rs.getString ("Email");
rs.close();
st.close();
}
catch (SQLException se) {
System.err.println("Threw a SQLException creating the list of blogs.");
System.err.println(se.getMessage());
}
return WhatIGot;
}
}