将 hdbuserstore 与 Java 应用程序一起使用

Use hdbuserstore with Java application

如何使用存储在 hdbuserstore 中的凭据连接到 HANA 数据库?

SAP docs中,为了使用jdbc驱动程序连接,提到了3种方法:

我无法弄清楚如何通过此驱动程序使用 hdbuserstore 密钥连接到 HANA 数据库。求推荐。

您可以使用 key(指定 hdbuserstore 的密钥)JDBC 属性。

假设您的 hdbuserstore 条目是:

hdbuserstore SET JOHN_DOE "127.0.0.1:35001@DB" dbUserName dbPassword

您可以使用以下方式连接:

import java.sql.*;
import com.sap.db.jdbc.Driver; 
public class Demo  {
    public static void main(String[] argv) {
        Connection connection = null;
        try {  
            java.util.Properties info = new java.util.Properties();
            // key mentioned in hdbuserstore
            info.put("key", "JOHN_DOE");
            connection = java.sql.DriverManager.getConnection("jdbc:sap://127.0.0.1:35001", info);
        }
        catch (SQLException e) {
            System.err.println(e);
            return;
        }
        if (connection != null) {
            // .... whatever
        }
    }
}

查看 SAP JDBC 属性列表 here