Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.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-运行脚本时出现原型错误_Java_Jdbc_Protocol Buffers - Fatal编程技术网

Java-运行脚本时出现原型错误

Java-运行脚本时出现原型错误,java,jdbc,protocol-buffers,Java,Jdbc,Protocol Buffers,我试图在intellij中运行以下代码,以便使用JDBC连接到数据库 import java.sql.*; public class DatabaseCompare { static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://hostname/databasena

我试图在intellij中运行以下代码,以便使用JDBC连接到数据库

    import java.sql.*;
    
    public class DatabaseCompare {
        static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
        static final String DB_URL = "jdbc:mysql://hostname/databasename";
        static final String USER = "user";
        static final String PASS = "databasepass";
    
        public DatabaseCompare() {
        }
    
        public static void main(String[] args) {
            Connection conn = null;
            Statement stmt = null;
    
            try {
                Class.forName("com.mysql.jdbc.Driver");
                System.out.println("Connecting to database...");
                conn = DriverManager.getConnection("jdbc:mysql://hostname/databasename", "user", "databasepass");
                System.out.println("Creating statement...");
                stmt = conn.createStatement();
                String sql = "SELECT c1, c2, c3, c4 FROM table";
                ResultSet rs = stmt.executeQuery(sql);
                rs.close();
                stmt.close();
                conn.close();
            } catch (SQLException var24) {
                var24.printStackTrace();
            } catch (Exception var25) {
                var25.printStackTrace();
            } finally {
                try {
                    if (stmt != null) {
                        stmt.close();
                    }
                } catch (SQLException var23) {
                }
    
                try {
                    if (conn != null) {
                        conn.close();
                    }
                } catch (SQLException var22) {
                    var22.printStackTrace();
                }
    
            }
            System.out.println("Goodbye!");
        }
    }
但在运行查询时,我会遇到100多个错误,如:

    - Error:(5264, 55) java: package com.google.protobuf.Descriptors does not exist
    - Error:(5267, 43) java: package com.google.protobuf.GeneratedMessageV3 does not exist
    - Error:(49, 26) java: package com.google.protobuf does not exist
    - Error:(118, 9) java: cannot find symbol
      symbol:   class UnusedPrivateParameter
      location: class com.mysql.cj.x.protobuf.MysqlxNotice.Frame
    - Error:(1113, 9) java: cannot find symbol
      symbol:   class UnusedPrivateParameter
      location: class com.mysql.cj.x.protobuf.MysqlxNotice.Warning
我还没有在网上找到关于如何解决此问题的任何相关信息

我怎样才能让它出现?
注:用户名和密码是为了演示,我在运行脚本时使用了真实凭据。

通过添加protobuff依赖项解决了问题:

 <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>3.13.0</version>
        </dependency>