java从Tomcat DBCP JDBC连接池获取连接对象
我有一个DataSource
,我从tomcat-dbcp
获得:
import java.sql.Connection
public Connection initPooledConnection()
{
try {
conn=(Connection)ds.getConnection();
if(conn==null)
{
System.out.println("Failed to initialize the connection");
}
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
如何继续使用com.mysql.jdbc.Statement
、com.mysql.jdbc.ResultSet
、com.mysql.jdbc.PreparedStatement
向mysql
发出请求
# 1 楼答案
下面是一个使用查询参数并使用结果的select查询示例