jdbcsql查询取消的java实现

3phpmpom  于 2021-06-27  发布在  Java
关注(0)|答案(0)|浏览(165)

我有两个oracle数据库示例,都是11g版本。
我编写了一个简单的java代码来执行一个查询,然后在它运行时取消它。。这是我的密码。

Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@mydb1:1521:orcl","username","***");

Statement stmt=con.createStatement();

new Thread(new Runnable() {
    private Statement tstmt;
    public Runnable init(Statement tstmt) {
        this.tstmt = tstmt;
        return this;
    }
    @Override
    public void run() {
        try{
            System.out.println("Running the thread....");
            Thread.sleep(1500);
            tstmt.cancel();
        }
        catch(InterruptedException e)
        {
            System.out.println("InterruptedException...");
        }
        catch(SQLException e)
        {
            System.out.println("SQLException...");
        }
    }
}.init(stmt)).start();

我基本上是在查询运行时调用statement.cancel,并希望在异常中处理它。当我对db1运行此命令时,会触发sqlexception。但是,它不会发生在db2上。
我不明白为什么行为上会有这种差异。是否有可以在数据库中启用/禁用的取消查询设置??

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题