简体   繁体   English

SAP HANA 找不到表/视图

[英]SAP HANA Could not find table/view

I am trying to connect HANA database which is running in Google Cloud Platform.我正在尝试连接在 Google Cloud Platform 中运行的 HANA 数据库。 Here is my java code,这是我的java代码,

try {
        Class.forName("com.sap.db.jdbc.Driver");
        String url = "jdbc:sap://myhost:39015/?";
        String user = "MYUSER";
        String password = "PASSWORD";
        System.out.println("Connecting to HANA..!");
        Connection cn = DriverManager.getConnection(url, user, password);
        System.out.println("Connection to HANA successful!");
        ResultSet rs = cn.createStatement().executeQuery("select * from \"TWEETS\"");
        rs.next();
        System.out.println(rs.getString(1));
    } catch (Exception e) {
        e.printStackTrace();
    }

The TWEETS table exists under SYSTEM schema, I can able to query TWEETS table using HANA sudio (Eclipse plugin). TWEETS表存在于SYSTEM模式下,我可以使用 HANA sudio(Eclipse 插件)查询TWEETS表。 But, when I try to query from java code the following exception occurs.但是,当我尝试从 java 代码中查询时,会发生以下异常。

com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [259] (at 14): invalid table name:  Could not find table/view TWEETS in schema SYSTEM: line 1 col 15 (at pos 14)
    at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.createException(SQLExceptionSapDB.java:334)
    at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.generateDatabaseException(SQLExceptionSapDB.java:165)
    at com.sap.db.jdbc.packet.ReplyPacket.buildExceptionChain(ReplyPacket.java:104)
    at com.sap.db.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:1110)
    at com.sap.db.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:854)
    at com.sap.db.jdbc.StatementSapDB.sendCommand(StatementSapDB.java:925)

Note: I tried below combinations as well, but no luck!注意:我也尝试了以下组合,但没有运气!

 1. "select * from TWEETS" 
 2. "select * from SYSTEM.TWEETS"
 3. "select * from \"TWEETS\" 
 4. "select * from \"SYSTEM\".\"TWEETS\""

table creation command,表创建命令,

    CREATE COLUMN TABLE TWEETS(
    "ID" INTEGER NOT NULL,
    "USER_NAME" NVARCHAR(100),
    "CREATED_AT" DATE,
    "TEXT" NVARCHAR (140),
    "HASH_TAGS" NVARCHAR (100),
    PRIMARY KEY("ID")
    );

Could you please help me to figure out the problem here?你能帮我解决这里的问题吗? Thanks!谢谢!

Following the documentation provided here , we can observe that there is a problem with the port that you've used in the SAP JDBC connection string.根据此处提供的文档,我们可以观察到您在 SAP JDBC 连接字符串中使用的端口存在问题。

The port should be 3 < instance number>15;端口应该是3<实例号>15; for example, 30015, if the instance is 00.例如,如果实例为 00,则为 30015。

By the above explanation, making the necessary changes in the connection string should resolve the issue.通过上述解释,对连接字符串进行必要的更改应该可以解决问题。

Corrected connection string is now the following (based on the parameters provided in the question):更正的连接字符串现在如下(基于问题中提供的参数):

String url = "jdbc:sap://myhost:30015/?databaseName=TWEETS&user=MYUSER&password=PASSWORD";

Hope this helps!希望这可以帮助!

尝试

"select * from SYSTEM.\"TWEETS\""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM