check if a connection is valid in IBatis

View: New views
3 Messages — Rating Filter:   Alert me  

check if a connection is valid in IBatis

by deligeli :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi

my code is like that:

public Clip getVideoById(String videoId)  throws SQLException{
                return (Clip) sqlMapper.queryForObject("getVideoById",videoId);
        }

how can i make sure that the connection to the database is valid and if not to open it?

Re: check if a connection is valid in IBatis

by deligeli :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi

i read that i should use PingQuery

what is it? how does it work? and how should i use it?

deligeli wrote:
hi

my code is like that:

public Clip getVideoById(String videoId)  throws SQLException{
                return (Clip) sqlMapper.queryForObject("getVideoById",videoId);
        }

how can i make sure that the connection to the database is valid and if not to open it?

Re: check if a connection is valid in IBatis

by NickSTL :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The ping options can be set in the config XML like so.  The Pool.* options are what you need.  This is just an example, you should set whatever timeout parameters you need (in ms).

<transactionManager type="JDBC">
                <dataSource type="SIMPLE">
                        <property name="JDBC.Driver" value="${driver}"/>
                        <property name="JDBC.ConnectionURL" value="${url}"/>
                        <property name="JDBC.Username" value="${user}"/>
                        <property name="JDBC.Password" value="${password}"/>
                       
                        <property name="Pool.TimeToWait" value="2000"/>
                                     <property name="Pool.PingQuery" value="SELECT 1"/>
                          <property name="Pool.PingEnabled" value="true"/>
                                <property name="Pool.PingConnectionsOlderThan" value="600000"/>
                        <property name="Pool.PingConnectionsNotUsedFor" value="600000"/>
                </dataSource>
        </transactionManager>

Hopefully this helps you!  Take a look at the javadoc for com.ibatis.common.jdbc.SimpleDataSource for the rull list of pool options.

Nick