Java ActionListerner中的ClassNotFoundException

Java ActionListerner中的ClassNotFoundException,java,jdbc,packaging,classnotfoundexception,Java,Jdbc,Packaging,Classnotfoundexception,我的button action Listener中有以下错误未报告异常ClassNotFoundException,我不确定如何解决它,我尝试添加ThrowClassNotFoundException,但在尝试编译时它仍然给我一个错误,我在 public void actionPerformed(ActionEvent e) throw ClassNotFoundException { //action listeners for Login in button and menu item

我的button action Listener中有以下错误未报告异常
ClassNotFoundException
,我不确定如何解决它,我尝试添加Throw
ClassNotFoundException
,但在尝试编译时它仍然给我一个错误,我在

public void actionPerformed(ActionEvent e) throw ClassNotFoundException {
//action listeners for Login in button and menu item
        submitButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {

                    DisplaySearch.Search(jtfImagename.getText(), jtfLocation.getText(), jtfTimestamp.getText());

                    String Iname = jtfImagename.getText();
                    String Loc = jtfLocation.getText();
                    String Time = jtfTimestamp.getText();
                    accountReportArea.setText("Search Criteria \n" + "Image name : " + Iname + "\nLocation : " + Loc + "\nTime Stamp : " + Time);                 
                } catch (SQLException ex) {
                    ex.printStackTrace();
                    //    JOptionPane.showMessageDialog(null,
                    //            "Sorry, couldn't check your credentials. Check the logs and report the problem to an administrator.");
                    return;
                }
            }
        });

DisplaySearch {
    // database URL                              

    static final String DATABASE_URL = "jdbc:mysql://localhost:3306/mysql";
    static final String USERNAME = "root";
    static final String PASSWORD = "root";

    // launch the application
    public static void Search(String imageName, String DateStamp, String imageTag) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        Connection connection = null; // manages connection
        Statement statement = null; // query statement
        ResultSet resultSet = null; // manages results

        // connect to database books and query database
        try {
            // establish connection to database
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            connection = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);

            // create Statement for querying database
            statement = connection.createStatement();

            // query database                                        
            resultSet = statement.executeQuery(
                    "SELECT imageName, DateStamp, imageTag FROM images");

            // process query results   
            System.out.println("Search Criteria");

            while (resultSet.next()) {
                String Tag = resultSet.getString(imageTag);
                String Date = resultSet.getString(DateStamp);
                String Name = resultSet.getString(imageName);
                System.out.print("Image Name: " + Name);
                System.out.print(", Date: " + Date);
                System.out.print(", Tag: " + Tag);
            } // end while
        } // end try
        catch (SQLException sqlException) {
            sqlException.printStackTrace();
        } // end catch                                                     
        finally // ensure resultSet, statement and connection are closed
        {
            try {
                resultSet.close();
                statement.close();
                connection.close();
            } // end try                                               
            catch (Exception exception) {
                exception.printStackTrace();
            } // end catch                                             
        } // end finally                                              
    } // end main
} // end class

通过添加
抛出ClassNotFoundException
您将无法解决任何问题。您只需向调用此函数的人指出,它可能引发这样的异常


因为您使用的是
Class.forName()
,所以应该在运行时包含
com.mysql.jdbc.Driver
。您的类路径中可能缺少一个JAR?

从哪里获得异常?
DisplaySearch.Search(jtfImagename.getText(),jtfilocation.getText(),jtfimestamp.getText())你为什么写
抛出
而不是
抛出
?Java区分大小写。添加
将抛出ClassNotFoundException
不会解决您的问题。如果是RCP应用程序,请确保已将所有必需的插件添加到产品配置中是否也需要将其添加到gui中?此行旨在创建
com.mysql.jdbc.Driver
实例。因此,运行程序时应包括
.class
文件。您的类路径中是否有名为
mysql-connector-java-x.x.x-bin.jar的文件?是的,我的类路径中有connect。