Sap hana 无效 table 名称
Sap hana invalid table name
我正在尝试使用 java 代码连接 hana 数据库,如下所示
try {
Class.forName("com.sap.db.jdbc.Driver");
String url = "jdbc:sap://host:30015/?";
String user = "myuser";
String password = "password";
System.out.println("try to connect to HANA !");
Connection cn = java.sql.DriverManager.getConnection(url, user, password);
System.out.println("Connection to HANA successful!");
ResultSet rs = cn.createStatement().executeQuery("select * from LIVE2.Connections");
rs.next();
System.out.println(rs.getInt(1));
} catch (Exception e) {
e.printStackTrace();
}
连接建立成功。并发生以下异常
com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [259] (at 20): invalid table name: Could not find table/view CONNECTIONS in schema LIVE2: line 1 col 21 (at pos 20)
at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.createException(SQLExceptionSapDB.java:345)
at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.generateDatabaseException(SQLExceptionSapDB.java:176)
at com.sap.db.jdbc.packet.ReplyPacket.buildExceptionChain(ReplyPacket.java:102)
at com.sap.db.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:1033)
at com.sap.db.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:823)
当我使用 hana studio 连接时,连接 table 存在于 Live2 架构中。
有什么问题的建议吗?
谢谢
SAP 文档有一个工作示例,URL 中有用于多数据库环境的数据库。
http://help.sap.com/saphelp_hanaplatform/helpdata/en/ff/15928cf5594d78b841fbbe649f04b4/content.htm
此处插入页面中的示例代码以使其简短。
import java.sql.*;
public class jdemo {
public static void main(String[] argv) {
Connection connection = null;
try {
connection = DriverManager.getConnection(
"jdbc:sap://myhdb:30715/?autocommit=false",myname,mysecret);
} catch (SQLException e) {
System.err.println("Connection Failed. User/Passwd Error?");
return;
}
if (connection != null) {
try {
System.out.println("Connection to HANA successful!");
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery("Select 'hello world' from dummy");
resultSet.next();
String hello = resultSet.getString(1);
System.out.println(hello);
} catch (SQLException e) {
System.err.println("Query failed!");
}
}
}
}
如果您有一个多数据库环境,JDBC url 应该如下所示
jdbc:sap://localhost:30013/?databaseName=tdb1&user=SYSTEM&password=manager
更新: 表列表可以通过 jdbc getTables() 调用获得,如此处所述 How to get all table names from a database?
我的猜测是:您创建了名称为 "Connections" 的 table(大小写字符。
现在,在您的代码中,您无需在名称两边加上引号,这会使 SAP HANA 执行其自动对象名称线性化:它会自动将所有字符设为大写。
这样您的查询将查找 CONNECTIONS,而 table 称为 Connections。
只需将它放在引号中,让它找到您的 table(或将 table 重命名为所有大写字母)。
- 拉斯
我正在尝试使用 java 代码连接 hana 数据库,如下所示
try {
Class.forName("com.sap.db.jdbc.Driver");
String url = "jdbc:sap://host:30015/?";
String user = "myuser";
String password = "password";
System.out.println("try to connect to HANA !");
Connection cn = java.sql.DriverManager.getConnection(url, user, password);
System.out.println("Connection to HANA successful!");
ResultSet rs = cn.createStatement().executeQuery("select * from LIVE2.Connections");
rs.next();
System.out.println(rs.getInt(1));
} catch (Exception e) {
e.printStackTrace();
}
连接建立成功。并发生以下异常
com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [259] (at 20): invalid table name: Could not find table/view CONNECTIONS in schema LIVE2: line 1 col 21 (at pos 20)
at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.createException(SQLExceptionSapDB.java:345)
at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.generateDatabaseException(SQLExceptionSapDB.java:176)
at com.sap.db.jdbc.packet.ReplyPacket.buildExceptionChain(ReplyPacket.java:102)
at com.sap.db.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:1033)
at com.sap.db.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:823)
当我使用 hana studio 连接时,连接 table 存在于 Live2 架构中。
有什么问题的建议吗?
谢谢
SAP 文档有一个工作示例,URL 中有用于多数据库环境的数据库。
http://help.sap.com/saphelp_hanaplatform/helpdata/en/ff/15928cf5594d78b841fbbe649f04b4/content.htm
此处插入页面中的示例代码以使其简短。
import java.sql.*;
public class jdemo {
public static void main(String[] argv) {
Connection connection = null;
try {
connection = DriverManager.getConnection(
"jdbc:sap://myhdb:30715/?autocommit=false",myname,mysecret);
} catch (SQLException e) {
System.err.println("Connection Failed. User/Passwd Error?");
return;
}
if (connection != null) {
try {
System.out.println("Connection to HANA successful!");
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery("Select 'hello world' from dummy");
resultSet.next();
String hello = resultSet.getString(1);
System.out.println(hello);
} catch (SQLException e) {
System.err.println("Query failed!");
}
}
}
}
如果您有一个多数据库环境,JDBC url 应该如下所示
jdbc:sap://localhost:30013/?databaseName=tdb1&user=SYSTEM&password=manager
更新: 表列表可以通过 jdbc getTables() 调用获得,如此处所述 How to get all table names from a database?
我的猜测是:您创建了名称为 "Connections" 的 table(大小写字符。
现在,在您的代码中,您无需在名称两边加上引号,这会使 SAP HANA 执行其自动对象名称线性化:它会自动将所有字符设为大写。
这样您的查询将查找 CONNECTIONS,而 table 称为 Connections。 只需将它放在引号中,让它找到您的 table(或将 table 重命名为所有大写字母)。
- 拉斯