1

I am getting a syntax error calling a HANA stored procedure. In the SQL editor in Hana Studio it works, but the syntax must be different for the prepareCall in Java. I think it's the forward slash after the package name, but not sure what to do about it.

Is it because I created the stored procedure under the Content folder? Should it be built somewhere else?

Here's the connection and call. The connection is fine

            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)
4
  • Have you tried replacing it with {call <your stored procedure>} as that is the JDBC escape which the driver converts to the server specific format. Also you use ' as a quote for the identifiers, in most database implementation the quote for quoted identifiers is a double quote ("), or sometimes a backtick (`). A single quote is generally reserved for string literals. Nov 7, 2013 at 20:57
  • Hi... yes.. I've tried it 100 ways.. no quotes/yes quotes, no package, yes package..... no quotes at all.... no schema, yes schema... every conceivable yes/no I can think of I've tried. Is it not possible thqt SAP have ONE example of calling a stored procedure that is explained and works? just ONE... I'm using the hana client jar, ng*.jar. I'm really tired of SAP bragging about the sea of help they have. It's a joke. It's nothing. Calling a stored procedure into HANA ought to be stupid-simple. It's the package syntax that's the problem I think. So, what's the syntax?
    – Davidson
    Nov 8, 2013 at 23:50
  • Unfortunately I don't know HANA, so I can't help you there (and googling doesn't seem to turn up useful information). Nov 9, 2013 at 6:50
  • I appreciate your reply and effort. I'll stay on it. There is an answer. When I do I'll return and put it here. It's a great thing to be able to access Hana via Java calls. It can be done, and I want to do it. Thanks again. It's something so simple, I'm sure.
    – Davidson
    Nov 9, 2013 at 14:43

1 Answer 1

0

The problem with my stored procedure call is that I didn't escape the double quotes. The syntax still needs the double quotes in order to properly handle the package and the forward slash. @Mark Rotteveel, you were close. I don't get to substitute single quotes for double quotes. This is what worked: cn.prepareCall("call \"_SYS_BIC\".\"myPackaged/ZMM_PR_MATERIALS_GET\"")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.