Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java-连接到MYSQL数据库try/catch的代码出错?_Java_Try Catch_Identifier - Fatal编程技术网

Java-连接到MYSQL数据库try/catch的代码出错?

Java-连接到MYSQL数据库try/catch的代码出错?,java,try-catch,identifier,Java,Try Catch,Identifier,我一辈子都搞不清楚代码中的错误是什么。有人有什么想法吗?所有的错误都出现在catch语句底部大约5行的地方 public void connectToDB(){ try { // this will load the MySQL driver, each DB has its own driver Class.forName(dbDriver); // setup the connection with the DB. connect = Dr

我一辈子都搞不清楚代码中的错误是什么。有人有什么想法吗?所有的错误都出现在catch语句底部大约5行的地方

public void connectToDB(){
    try {
    // this will load the MySQL driver, each DB has its own driver
      Class.forName(dbDriver);
      // setup the connection with the DB.
      connect = DriverManager
          .getConnection("jdbc:mysql://localhost/?"
              + "user=root&password=");
    ResultSet resultSet = connect.getMetaData().getCatalogs();

    //iterate each catalog in the ResultSet
    while (resultSet.next()) {
      // Get the database name, which is at position 1
      String databaseName = resultSet.getString(1);
      if (databaseName.equals("Ballers")) {
          preparedStatement = connect.prepareStatement("DROP DATABASE Ballers");
          preparedStatement.execute();
      }
    }
          ScriptRunner runner = new ScriptRunner(connect, false, false);
          try {
            runner.runScript(new BufferedReader(new FileReader(dumpPath)));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } catch (ClassNotFoundException | SQLException e) {
        System.out.println("not connecting");
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}
错误内容如下:

DatabaseHelper.java:64: <identifier> expected
        } catch (ClassNotFoundException | SQLException e) {
                                       ^
DatabaseHelper.java:64: '{' expected
        } catch (ClassNotFoundException | SQLException e) {
                                         ^
DatabaseHelper.java:64: not a statement
        } catch (ClassNotFoundException | SQLException e) {
                                                       ^
DatabaseHelper.java:64: ';' expected
        } catch (ClassNotFoundException | SQLException e) {
DatabaseHelper.java:64:应为
}catch(ClassNotFoundException | SQLException e){
^
DatabaseHelper.java:64:“{”应为
}catch(ClassNotFoundException | SQLException e){
^
java:64:不是语句
}catch(ClassNotFoundException | SQLException e){
^
DatabaseHelper.java:64:“;”应为
}catch(ClassNotFoundException | SQLException e){

需要什么标识符?这不是有效语句吗?

以这种方式它是有效的。由于出现此错误,您必须使用Java的早期版本。

您必须使用Java的odler版本

从Java 7开始,支持多个异常捕获。您必须单独捕获它们

皈依

} catch (ClassNotFoundException | SQLException e) {
        System.out.println("not connecting");
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


您正在干扰Java环境。请检查JRE设置。如果您使用JDK7,它将正常工作。非常感谢。我更新到Java7 update 65并重新启动了编译器,它正常工作。非常感谢您对问题的解释,以及如果我决定不使用Java7,如何修复它。
} catch (ClassNotFoundException  e) {
        System.out.println("not connecting");
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
} catch ( SQLException e) {
        System.out.println("not connecting");
        // TODO Auto-generated catch block
        e.printStackTrace();
    }