Skip to Content
0

JDBC call to hana stored procedure with DML queries

Jul 04, 2017 at 10:03 AM

80

avatar image

Hi folks,

I was trying to call a hana stored procedure from JDBC. I was able execute stored procedures which contained simple data definition sql.

But when the stored procedure contained data manipulation sql, like update and insert, even though the jdbc class runs successfully, I don't see any changes in the hana stored tables that were supposed to be updated from the stored procedure itself.

public static void main(String[] args) {
		SpringApplication.run(CallprocApplication.class, args);

		String user = "SYSTEM";
		String pwd = "******";
		//connect
	      Connection connection = null;
	      try {
	         connection = DriverManager.getConnection(
	            "jdbc:sap://localhost:30115/?autocommit=false",user,pwd);
	      } catch (SQLException e) {
	         System.err.println("Connection Failed. User/Passwd Error?");
	         return;
	      }
	      if (connection != null) {
	         try {
	            System.out.println("Connection to HANA successful!");
	        	CallableStatement stmt = connection.prepareCall("{CALL \"SYSTEM\".\"CALLJDBC\"()}");
	    			 stmt.executeUpdate();
		            System.out.println("executed!");
//		            stmt.close();
	    		} catch (SQLException e) {
	    			// TODO Auto-generated catch block
	    			e.printStackTrace();
	    		}
	     }
	   }

The called stored procedure contains just a bunch of insert statements with no IN or OUT parameters.

Is there a special way to execute sql insert/update statements from jdbc?

Any suggestions would be great!

Regards,

Devam

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
ANIRUDDHA SHINDE Jul 12, 2017 at 05:38 AM
2

Hi

In Your JDBC call you have autocommit property set as false , either set this as true if you do not want explicit commit after dml statement , and in case you want this as false then use explicit commit.

DriverManager.getConnection("jdbc:sap://localhost:30115/?autocommit=false",user,pwd);

thanks

Aniruddha Shinde

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks for pointing out.

Now I want to replace the "localhost" with ip address for access of the hana db from remote systems so as to call a procedure remotely. But when i use the new jdbc url with the ip address, I get a connection timeout.

The url looks like: "jdbc:sap://10.117.96.116:30065/?autocommit=true"

Am i missing out on some configurations?

Thanks,

Devam

0