根据谷歌和其他一些消息来源(例如http://www.enterprisedt.com/publications/oracle/result_set.html),如果我想调用一个返回引用游标的存储函数,我需要写一些像这是为了访问ResultSet:
String query = "begin ? := sp_get_stocks(?); end;";
CallableStatement stmt = conn.prepareCall(query);
// register the type of the out param - an Oracle specific type
stmt.registerOutParameter(1, OracleTypes.CURSOR);
// set the in param
stmt.setFloat(2, price);
// execute and retrieve the result set
stmt.execute();
ResultSet rs = (ResultSet)stmt.getObject(1);
无论如何都没有在Oracle上引入编译时依赖性.是否有OracleTypes.CURSOR的通用替代方案?
设置游泳池的最佳方法是: -
我认为这是一个不可知的问题,但欢迎对特定数据库/语言的"特征"发表评论.例如,在某些数据库上连接可能比其他数据库更慢或更昂贵.
为了澄清,我不打算从头开始编写池,这个问题更多的是关于如何配置实现池的现有库.
我们在嘲笑了一段时间(几个小时)后得到了一个CommunicationsException(来自DBCP).错误消息(在Exception中)是在这个问题的结尾 - 但我没有看到在任何配置文件中定义wait_timeout.(我们应该在哪里看?在tomcat/conf目录之外的某个地方?).
其次,正如Exception所建议的那样,在哪里放置"Connector/J连接属性'autoReconnect = true'"?这是tomcat设置文件conf/context.xml中的资源定义:
<Resource name="jdbc/TomcatResourceName" auth="Container" type="javax.sql.DataSource"
           maxActive="100" maxIdle="30" maxWait="10000"
           removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"
           username="xxxx" password="yyyy"
           driverClassName="com.mysql.jdbc.Driver"
           url="jdbc:mysql://127.0.0.1:3306/dbname?autoReconnect=true"/>
第三,为什么JVM会等到executeQuery()调用抛出异常?如果连接超时,getConnection方法应该抛出异常,不应该吗?这是我正在讨论的源代码部分:
        try {
                conn = getConnection (true);
                stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,
                                                ResultSet.CONCUR_READ_ONLY);
                rset = stmt.executeQuery (bQuery);
                while (rset.next()) {
                     ....
最后,这里是Stack跟踪的前几行......
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 84,160,724 milliseconds ago.  The last packet sent successfully to the server was 84,160,848 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring …哪一个是使用的更好的方法MySQL中Tomcat:
 
    A)只要它的会话有效分配的用户数据库连接.[OR]
 
    B)打开与DB的连接,每次请求都会到达服务器,当它关闭时.
    C)连接池.[最佳答案]