使用JDBC在HANA中调用HANA存储过程时出现语法错误

时间:2013-11-07 20:08:30

标签: java jdbc hana

调用HANA存储过程时出现语法错误。在Hana Studio的SQL编辑器中它可以工作,但Java中的prepareCall的语法必须不同。我认为它是包名后面的正斜杠,但不知道如何处理它。

是因为我在Content文件夹下创建了存储过程吗?它应该建在其他地方吗?

这是连接和通话。连接很好

            Class.forName("com.sap.db.jdbc.Driver");

            String url = "jdbc:sap://10.9.9.139:30015/GL1";
            String user = "userid";
            String password = "password";

            cn = java.sql.DriverManager.getConnection(url, user, password);

            if (cn == null) {
                System.out.println("failed");
            }

            cs = cn.prepareCall("call '_SYS_BIC'.'myPackaged/ZMM_PR_MATERIALS_GET'"); <---- THROWS EXCEPTION BELOW
            rs = cs.executeQuery();
            while(rs.next()) {
                System.out.println(rs.getString(0));
            }
        } catch(Exception e) {
            e.printStackTrace();
        }

// this WORKS FINE... i get a connection and get some records.    
//          rs = cn.createStatement().executeQuery("SELECT * FROM MYSCHEMA.ORDERS");
//          int i = 0;
//          while (rs.next()) {
//              System.out.println(String.format("rec %2d: %s=%2s", ++i, "ORDER_ID", rs.getString("ORDER_ID")));
//          }



com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "_SYS_BIC": line 1 col 6 (at pos 6)
    at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.createException(SQLExceptionSapDB.java:334)
    at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.generateDatabaseException(SQLExceptionSapDB.java:174)
    at com.sap.db.jdbc.packet.ReplyPacket.buildExceptionChain(ReplyPacket.java:104)
    at com.sap.db.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:1106)
    at com.sap.db.jdbc.CallableStatementSapDB.sendCommand(CallableStatementSapDB.java:1961)
    at com.sap.db.jdbc.StatementSapDB.sendSQL(StatementSapDB.java:972)
    at com.sap.db.jdbc.CallableStatementSapDB.doParse(CallableStatementSapDB.java:253)
    at com.sap.db.jdbc.CallableStatementSapDB.constructor(CallableStatementSapDB.java:212)
    at com.sap.db.jdbc.CallableStatementSapDB.<init>(CallableStatementSapDB.java:123)
    at com.sap.db.jdbc.CallableStatementSapDBFinalize.<init>(CallableStatementSapDBFinalize.java:31)
    at com.sap.db.jdbc.ConnectionSapDB.prepareCall(ConnectionSapDB.java:1295)
    at com.sap.db.jdbc.trace.Connection.prepareCall(Connection.java:318)
    at com.glazers.hana.utils.HanaStoredProcedure.execute(HanaStoredProcedure.java:54)
    at com.glazers.hana.utils.HanaStoredProcedure.main(HanaStoredProcedure.java:20)

1 个答案:

答案 0 :(得分:0)

我的存储过程调用的问题是我没有转义双引号。语法仍然需要双引号才能正确处理包和正斜杠。 @Mark Rotteveel,你很亲密。我不会用双引号替换单引号。这是有用的:cn.prepareCall(“call \”_ SYS_BIC \“。\”myPackaged / ZMM_PR_MATERIALS_GET \“”)

相关问题