ivr IVR Tutorial Table of Content << Previous  >> Next

9.2 The Java Class to Check Password Using JDBC

The class for checking 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.
            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;

        catch (Exception e) {
        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)

        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 voicent

This 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 123

If everything works, you should see the following printout:

The result is: true

If you are using Microsoft SQL Server, please make sure you have enabled the TCP/IP connection for your database. Select Microsoft SQL Server 2005>Configuration Tools>SQL Server Configuration Manager. In the SQL Server Configuration Manager select the node SQL Server 2005 Network Configuration>Protocols for SQLEXPRESS. Right-click on the TCP/IP node and select Enable. Restart the SQL Server (SQLEXPRESS) service. In Adminstrative Tools>Services, right-click on the SQL Server (SQLEXPRESS) service and select Restart.

Connection URL for the default SQL Server 2005 database is jdbc:sqlserver://localhost:<port>. In the connection URL, <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 node SQL Server 2005 Network Configuration > Protocols for SQLEXPRESS. Right-click on TCP/IP node and select Properties. Select the IP Addresses tab. In IP ALL, the TCP Dynamic Ports specifies the <port> value.


ivr IVR Studio Table of Content << Previous >> Next