<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Help me on the class query database in CVP</title>
  <link rel="alternate" href="http://developer.cisco.com/c/message_boards/find_thread?p_l_id=&amp;threadId=1432309" />
  <subtitle>Help me on the class query database in CVP</subtitle>
  <id>http://developer.cisco.com/c/message_boards/find_thread?p_l_id=&amp;threadId=1432309</id>
  <updated>2013-05-23T09:45:36Z</updated>
  <dc:date>2013-05-23T09:45:36Z</dc:date>
  <entry>
    <title>Help me on the class query database in CVP</title>
    <link rel="alternate" href="http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=1432308" />
    <author>
      <name>Doan Khanh Tan Thanh</name>
    </author>
    <id>http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=1432308</id>
    <updated>2009-06-16T08:32:05Z</updated>
    <published>2009-06-16T08:32:05Z</published>
    <summary type="html">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;
  }

}</summary>
    <dc:creator>Doan Khanh Tan Thanh</dc:creator>
    <dc:date>2009-06-16T08:32:05Z</dc:date>
  </entry>
</feed>

