Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to execute SQL Script file through JDBC connection

Hi,

I am able to save the SQL Commands in a file and call them using following command in hana client.

\i "pth/filename.txt" in command line.

Is there a way to execute the same through java code using a jdbc connection.  Kindly share the code snippet.

I created statement object and callablestatement object.

I am getting the following exception

com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "\": line 1 col 2 (at pos 2)

  at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.createException(SQLExceptionSapDB.java:345)

  at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.generateDatabaseException(SQLExceptionSapDB.java:185)

  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.CallableStatementSapDB.sendCommand(CallableStatementSapDB.java:1790)

  at com.sap.db.jdbc.StatementSapDB.sendSQL(StatementSapDB.java:945)

  at com.sap.db.jdbc.CallableStatementSapDB.doParse(CallableStatementSapDB.java:185)

  at com.sap.db.jdbc.CallableStatementSapDB.constructor(CallableStatementSapDB.java:144)

  at com.sap.db.jdbc.CallableStatementSapDB.<init>(CallableStatementSapDB.java:89)

  at com.sap.db.jdbc.CallableStatementSapDBFinalize.<init>(CallableStatementSapDBFinalize.java:31)

  at com.sap.db.jdbc.ConnectionSapDB.prepareCall(ConnectionSapDB.java:1238)

  at com.sap.db.jdbc.trace.Connection.prepareCall(Connection.java:328)

  at mypackage.mypgm.main(Import.java:24)

Regards,

Subramanian S.

Tags:
Not what you were looking for? View more on this topic or Ask a question