首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用单个JDBC语句对象执行多个查询

使用单个JDBC语句对象执行多个查询
EN

Stack Overflow用户
提问于 2014-01-24 15:38:13
回答 2查看 87.6K关注 0票数 28

在JDBC中,可以使用单个Statement对象多次调用executeQuery("")吗?安全吗?或者,我应该在每次查询后关闭statement对象,然后创建新对象来执行另一个查询。

例如:

Connection con;
Statement s;
ResultSet rs;
ResultSet rs2;
try
{
    con = getConnection();
    s = con.prepareStatement();

    try
    {
        rs = s.executeQuery(".......................");

        // process the result set rs
    }
    finally
    {
        close(rs);
    }

    // I know what to do to rs here
    // But I am asking, should I close the Statement s here? Or can I use it again for the next query?

    try
    {
        rs2 = s.executeQuery(".......................");

        // process the result set rs2
    }
    finally
    {
        close(rs2);
    }
}
finally
{
    close(s);
    close(con);
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21327012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档