Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8944

How to connect to My HDB Server using JDBC

$
0
0

Hi Experts,

 

I am trying to connect to my SAP HANA DB Server with following code.

 

package connection;

import java.sql.*;

public class ServerCon {

   public static void main(String[] argv) {

      Connection connection = null;

      try {         

          try{

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

          }catch (Exception e) {

              e.printStackTrace();

          }

        

         connection = DriverManager.getConnection(

            "jdbc:sap://xx.xxx.xxx.xxx:30015/","SAP PID as user name","SAP DB Password");   

 

      } catch (SQLException e) {

          e.printStackTrace();

         System.err.println("Connection Failed. User/Passwd Error?");

         return;

      }

 

      if (connection != null) {

         try {

            System.out.println("Connection to HANA successful!");

            Statement stmt = connection.createStatement();

            ResultSet resultSet = stmt.executeQuery("Select 'hello world' from dummy");

            resultSet.next();

            String hello = resultSet.getString(1);

            System.out.println(hello);

       } catch (SQLException e) {

          System.err.println("Query failed!");

       }

     }

   }

}

 

 

 

Using the above code i am getting the following exception:

 

 

com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: Cannot connect to jdbc:sap://xx.xxx.xxx.xxx:30015/ [Cannot connect to host xx.xxx.xxx.xxx:30015 [Connection refused: connect], -813.].

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

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

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

    at com.sap.db.jdbc.Driver.connect(Driver.java:192)

    at java.sql.DriverManager.getConnection(Unknown Source)

    at java.sql.DriverManager.getConnection(Unknown Source)

    at connection.ServerCon.main(ServerCon.java:14)

 

 

 

Could you please let me know what could be the issue here? i dont know i am giving correct host name and port also. I have taken host name from my eclipse as follows:

 

 

Thank you very much in advance..


Viewing all articles
Browse latest Browse all 8944

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>