on 07-25-2017 11:55 AM - last edited on 02-03-2024 10:26 PM by postmig_api_4
Hi,
I am trying to connect HANA database using below java code,
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();
}<br>
It connects HANA database successfully. But the following exception occurs.
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)<br>
The TWEETS
table exists under SYSTEM
schema which I can able to query using HANA sudio (Eclipse plugin). But, I couldn't able to query the table using above java code.
Please help me to resolve this issue.
P.S : I tried below combinations as well to query TWEETS
table. But no luck!
<code>1. "select * from TWEETS"
2. "select * from SYSTEM.TWEETS"
3. "select * from \"TWEETS\"
4. "select * from \"SYSTEM\".\"TWEETS\""
are you connecting to right system, this could be possible that the connection you are making to hana instance in java code is different than what you you are accessing in hana studio, this is one off possibility.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Michael,
you must include schema name on your query ex :
select * from YOUR_SCHEMA.\"TWEETS\"");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's only required if the table is in a different schema than the current one. Per the description, the table is in the SYSTEM schema (bad practice!) and the connection is done with the SYSTEM user (worse practice!) so the name resolution does not require an explicit schema name in this case.
Hi,
The case of the table name is important as well.
Can you check if in the system schema, the TWEETS table is all caps.
Or if possible can you post an image of the catalog from Studio.
Thank you.
Best Regards,
Anjali.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
9 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.