Advanced IVR Tutorial Lesson 2: Java Class using JDBC
The class for checking the password is listed below:
package voicent.ivrsample;import java.sql*;
public class
MyDbPasswordChecker
{
// Replace the following with your settings
// This CONN_URL uses Microsoft SQL Server 2005
static final String CONN_URL = "jdbc:sqlserver://localhost:2424;databaseName=AP;";
static final String DB_USER = "use your db user name";
static final String DB_PASSWORD = "use your db password";
// to return multiple values, use java.util.Properties as return
type
// please see ivr studio tutorial or document for more details
public boolean check(String accountNumber,
String passwd)
{
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
boolean passwdOK = false;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(CONN_URL, DB_USER, DB_PASSWORD);
// Create and execute an SQL statement
String sqlst = "SELECT Account_Password FROM AccountPassword " +
" WHERE Account_Id = '" + accountNumber + "'";
stmt = con.createStatement();
rs = stmt.executeQuery(sqlst);
// Check the return data
if (rs.next()) {
String passwdSaved = rs.getString(1).trim();
if (passwdSaved.equals(passwd.trim()))
passwdOK = true;
}
rs.close();
stmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (con != null)
try { con.close(); }
catch(Exception e) {}
}
return passwdOK;
}
// test and customize this program independent of IVR Studio
// requires MSSQL 2005 JDBC driver library: sqljdbc.jar (free
download from microsoft)
public static void main(String args[])
{
if (args.length < 2)
return;
MyDbPasswordChecker checker = new MyDbPasswordChecker();
boolean rc = checker.check(args[0], args[1]);
System.out.println("The result is: " + Boolean.toString(rc));
}
}
You should be able to compile and run this class independent of IVR Studio.
Compile The Java Class
To compile, use the following command:
javac -classpath "C:\Program Files\Voicent\IVRStudio\samples\sqljdbc.jar" -d. MyDbPasswordChecker.java
This compiles the Java class in the current directory. The compiled class will be saved under the ./voicent/sample directory.
Please note that you need to supply the correct values before compiling:
static final String CONN_URL = "jdbc:sqlserver://localhost:2424;databaseName=AP;";static final String DB_USER = "use your db user name";
static final String DB_PASSWORD = "use your db password";
Make a Jar File
Use the following command to make a jar file:
javac -cvf dbinteg.jar voicentThis will put all files under ./voicent directory into the dbinteg.jar file.
Run the Program
You can run the program using the following command:
java -classpath "C:/Program Files/Voicent/IVRStudio/samples/sqljdbc.jar;dbinteg.jar" voicent.sample.MyDbPasswordChecker 101 123If everything works, you should see the following printout:
The result is: trueIf you are using Microsoft SQL Server, please make sure you have enabled the TCP/IP connection for your database. Select
In the SQL Server Configuration Manager select the node Right-click on the and select . Restart the service. InConnection URL for the default SQL Server 2005 database is <port> is obtained from the SQL Server configuration Manager. When the SQL Server 2005 SQLEXPRESS is restarted the port number changes. To obtain the <port> in the SQL Server Configuration Manager, select the . Right-click on and select . Select the tab. In , the specifies the value.
In the connection URL,