[英]how to set Connection Timeout with jndi?
i have this code: 我有这个代码:
Object objc = null;
if (jdbcFactory == null) {
try {
InitialContext c = new InitialContext();
this.jdbcFactory = (DataSource) c.lookup(this.jndiName);
}
catch (Exception e) {
Logger log = Logger.getLogger(this.getClass());
}
}
// jdbcFactory initiated.
try {
objc = this.jdbcFactory.getConnection();
} catch (Exception e) {
}
return objc;
}
how can i set connection timeout ? 如何设置连接超时? (without using context.xml ) (不使用context.xml)
According to your code you are casting the this.jdbcFactory
to the javax.sql.DataSource
; 根据您的代码,您正在将this.jdbcFactory
转换为javax.sql.DataSource
; according to the code this interface extends javax.sql.CommonDataSource
which defines the following method javax.sql.CommonDataSource#setLoginTimeout
根据该接口的代码,扩展了javax.sql.CommonDataSource
,它定义了以下方法javax.sql.CommonDataSource#setLoginTimeout
This method documentation states that it: 该方法文档指出:
* <p>Sets the maximum time in seconds that this data source will wait
* while attempting to connect to a database. A value of zero
* specifies that the timeout is the default system timeout
* if there is one; otherwise, it specifies that there is no timeout.
* When a <code>DataSource</code> object is created, the login timeout is
* initially zero.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.