ConnectionManager Class
This class implements a JDBC connection pool. An instance of this class can be obtained from the IVR.getDb() method. The configuration for the JDBC connection may be set at [Options] > [Advanced], as below:
db1.driver=com.mysql.jdbc.Driver db1.url=jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=UTF-8 db1.user=root db1.password=root
Example of how to use ConnectionManager class:
function sampleDbAccess( ivr ){ var db = ivr.getDb( 'db1' ); var con = db.getConnection(); var st; var rs; try{ var tel = ivr.getOtherNumber(); var sql = "SELECT member_id FROM membertalbe WHERE tel='" + tel + "'"; con.setAutoCommit( true ); st = con.createStatement(); rs = st.executeQuery( sql ); var memberid = ""; if( rs.next() ){ memberid = rs.getString( 1 ); } if( memberid.length < 10 ){ //she/he is not a member. ivr.dropCall(); return; } anotherMethod( ivr, cid ); // call another method to process something. }finally{ db.close( st ); db.close( rs ); db.close( con ); }
Methods:
void close( java.sql.Connection con )
Description: Call the con.close() method if not null
The physical connection might not be closed and could be recycled if the given connection is a pooled connection.
Parameters:
con: JDBC connection
void close( java.sql.Statement st )
Description: Call the st.close() method if not null.
Parameters:
st: JDBC Statement object
void close( java.sql.ResultSet rs )
Description: Call the rs.close() method, if not null
Parameters:
rs: JDBC ResultSet object
sql.Connection getConnection()
Description: Gets a JDBC connection from the connection pool
Return: A JDBC connection
Related Links: