【问题标题】:UnsupportedOperationException in Java when checking whether the resultSet is Closed or not [duplicate]检查结果集是否关闭时Java中的UnsupportedOperationException [重复]
【发布时间】:2016-08-06 18:03:26
【问题描述】:

我在检查 ResultSet 是否关闭时遇到错误,这是我在 netbeans 7.3 中遇到的实际错误:

线程“AWT-EventQueue-0”中的异常 java.lang.UnsupportedOperationException:尚不支持操作 在 sun.jdbc.odbc.JdbcOdbcResultSet.isClosed(JdbcOdbcResultSet.java:6753)

这是我得到错误的代码。

try{
    if(!rs.isClosed());
    rs.close();
}catch(SQLException ex){
    JOptionPane.showMessageDialog(rootpane, ex);
}

提前感谢您的帮助。

【问题讨论】:

  • 您使用的是什么 JDBC 驱动程序?
  • 我正在使用 JDBC-ODBC 驱动程序。
  • Andremoniy 的问题是他没有给出发生错误的 JAVA 代码,我只是无法理解提问者显示的 HTML 代码,所以我发布了我自己的问题。

标签: java resultset jdbc-odbc


【解决方案1】:

显然,驱动程序没有实现该方法并抛出java.lang.UnsupportedOperationException。根据供应商(Oracle、IBM、Derby 等),它可以实现 JDBC 的某些功能。你只能关闭连接。这释放了所有资源。

【讨论】:

  • 你是想说我不应该使用 if 条件吗?
  • 或者您可以使用不同的驱动程序,一个实现isClosed() 方法的驱动程序。您使用的是通用驱动程序,但您正在使用的数据库(MySQL、MS Server、Oracle、Derby...)有特定的驱动程序,它们是比通用驱动程序更好的解决方案。
  • 问题是我什至使用了你告诉的方式,但是在关闭 ResultSet 时我遇到了同样的错误,它已关闭,有趣的是我还使用了 resultSet 中的数据,所以它是如何关闭的.
  • 无需关闭。应用完成使用后关闭连接即可。
【解决方案2】:
package audio;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JButton;
import javax.swing.JFrame;
import javazoom.jl.player.Player;


public class sound4 extends JFrame implements ActionListener{
   MediaPlayer mediaPlayer;
    JButton button,button2;
    Player player;
    Clip clip ;

    public sound4()
    {
        setLayout(new FlowLayout());
        setSize(300,300);
         button =new JButton("Click me");
       add(button);
       button.addActionListener(this);
       button2 =new JButton("exit");
       add(button2);
       button2.addActionListener(this);
    }

    public static void main(String[] args)
    {


           java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new sound().setVisible(true);
            }
        });


    }

    @Override
    public void actionPerformed(ActionEvent e) {

        if(e.getSource()==button)
        {
        /*String bip = "music1.mp3";
Media hit = new Media(bip);
 mediaPlayer = new MediaPlayer(hit);
 mediaPlayer.play();
 if(e.getSource()==button2)
        {
            mediaPlayer.dispose();
        }


        }*/


            //int alarmname =  cmbalarm.getSelectedIndex();

 // String playalarm = "";//String.valueOf(alarmname)+ ".wav";
  try{
         //if (cmbalarm.getSelectedIndex()==alarmname){
     AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File("C:\\Users\\nida\\Music\\music1.mp3"));
        clip = AudioSystem.getClip();
       clip.open(inputStream);
        //clip.start();


       if(e.getSource()==button2)
            {
               clip.close();
               clip.stop();
              // System.exit(0);

            }
        else
        {
             clip.loop(Clip.LOOP_CONTINUOUSLY);
        }
       Thread.sleep(10000);
    }
     catch (Exception ex) {
       }


    }



    }
}
Am trying to run Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
    at audio.sound.actionPerformed(sound.java:81)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6535)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6300)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4891)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
this code but it gives that errors.

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 2018-03-10
    • 2017-05-24
    • 2014-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-09
    相关资源
    最近更新 更多