JDBC:通过单个数据库调用返回多个结果集-不适用于Oracle [英] JDBC : returning multiple result sets via a single database invocation - not working for Oracle

查看:146
本文介绍了JDBC:通过单个数据库调用返回多个结果集-不适用于Oracle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇帖子显示了在单个JDBC调用中执行多个查询(针对SQL Server数据库),方法是使用分号将它们分开.当我尝试对Oracle 10G执行相同操作时,出现了无效字符"错误:

This post showed executing multiple queries in a single JDBC invocation (against a SQL Server database) by separating them with semicolons. When I tried to do the same with Oracle 10G, an error "invalid character" propped up :

class db
{
    public static void main(String aa[])throws Exception
    {
        Class.forName("oracle.jdbc.driver.OracleDriver"); 
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//192.168.10.29:1521/ttt","username","password");
        PreparedStatement stat = conn.prepareStatement("select voila from app where rownum<4; select code from process where rownum<4");
        stat.execute();
        while (stat.getMoreResults()){
            ResultSet rs = stat.getResultSet();
            while (rs.next()){
                System.out.println(rs.getString(1));        
            }
        }
        conn.close();
    }
}

我在做什么错了?

推荐答案

您没有做错任何事情(除非假定所有DBMS都工作相同)

You are doing nothing wrong (except to assume that all DBMS work the same)

Oracle(及其JDBC驱动程序)根本不支持此功能.

Oracle (and its JDBC driver) simply does not support this.

您需要单独运行每个SELECT.

You need to run each SELECT individually.

顺便说一句:这是某些SQL注入攻击无法与Orace一起使用的原因之一-尤其是著名的"小鲍比表"卡通.

Btw: this is one of the reason that some SQL injection attacks don't work with Orace - especially the famous "little bobby tables" cartoon.

这篇关于JDBC:通过单个数据库调用返回多个结果集-不适用于Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆