Skip to Content

Hello folks,

In this document, I will write the basic java program to connect to HANA Database and retrieve the information. I am going to consume the data model which I created using “graphical” editor of “Calculation View”. The target of this document is to make you understand the how we can connect to the models in HANA database with JAVA.

With this we can feel the power of united SAP and JAVA.

I have created a view called “CALC_VIEW” using graphic editor of calculation view as shown below:

A241.jpg

In this view am trying to “Union” two tables “NYSE” and “NYSE_1” as you can see above. Now we have to launch eclipse IDE to write our java program.

A242.jpg

JAVA CODE:

import java.sql.*; 
    public class Connection 
          { 
           public static void main(String args[]) 
           { 
                try 
                  { 
                  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
                  java.sql.Connection conn=DriverManager.getConnection("jdbc:odbc:HANA","userid","pwd"); 
                  Statement stmt = conn.createStatement(); 
                  ResultSet rs = stmt.executeQuery( "SELECT * FROM \"_SYS_BIC\".\"package/CALC_GRAPHIC\"" ); 
                   while( rs.next() ) 
                   { 
                         System.out.println( rs.getString(1)); 
                         System.out.println( rs.getString(2));  
                   } 
                   rs.close() ; 
                   stmt.close() ; 
                   conn.close() ; 
                   } 
                  catch(Exception e) 
                  { 
                         System.out.println(e); 
                  } 
           } 
    }  

See we can now see fetched the records from “CALC_GRAPHIC” view using this java program as shown below:

A243.jpg

Thank your reading this blog 🙂 Do add your valuable suggestions to this document 🙂

To report this post you need to login first.

10 Comments

You must be Logged on to comment or reply to a post.

    1. Lalitha Swaroop Krishna Tangudu Post author

      Hello Thomas,

       

      Thank you for mentioning it. I missed to mention it. I have one more doubt. Will PHP work on top of HANA DB? Am able to connect but “SQL” statements not getting executed. Will these be available in future versions of HANA?

       

      Regards,

      Krishna Tangudu

      (0) 
      1. Thomas Jung

        We do want to open development to other platforms and techniques in the future.  At some point we will support the ODBC/JDBC drivers for 3rd party development. I really couldn’t say if it will work in PHP, however, because I don’t know what technical problems you are hitting.

        (0) 
  1. Rajarshi Muhuri

    Krishna

     

    Very nice… first of its kind blog….

    Now I got a question , I am getting this error

     

    java.lang.ClassNotFoundException: com.sap.db.jdbc.Driver

     

    which means , its not being able to dynamically load the jdbc driver ..

     

    Nor does your class path work for me ..

     

    Can you elaborate on the lines below , and perhaps give suggestions

     

     

    1.                   Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);   
    2.                   java.sql.Connection conn=DriverManager.getConnection(“jdbc:odbc:HANA”,“userid”,“pwd”);   
    (0) 

Leave a Reply