cancel
Showing results for 
Search instead for 
Did you mean: 

How to Run the java code in Hana SP 12 ?

former_member250641
Participant
0 Kudos

Hi Expert ,

How to run this sample java code to understand whether  it connected the Hana db or not ?

import java.sql.*;

public class jdemo {

  public static void main(String[] argv) {

  Connection connection = null;

  try { 

  connection = DriverManager.getConnection(

  "jdbc:sap://myhdb:30715/?autocommit=false",myname,mysecret); 

  } catch (SQLException e) {

  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!");

  }

  }

  }

}

Thanks,

Sumit

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member250641
Participant
0 Kudos

Hi Nikloy ,

I try to push my code , but there also i am facing error .



Could you please me on this .


Thanks,

Sumit

Former Member
0 Kudos

Hi Sumit,

It looks like the push is trying to upload a lot of files to XSA, around 1.74 GB.

This usually happens when you do not specify the path to the web application.

You could specify the application in two ways:

1) On the command line

xs push <app_name> -p path/to/web/app/<name>.war

2) In the manifest file. If you have created a manifest file:

---

applications:

- name: <app_name>

  memory: 512m

  instance: 1

  path:  path/to/web/app/<name>.war

Then you could push you application with the following command:

xs push -f manifest.yml

After you have pushed your application in the output you will get the URL with which you could access you app. It would look something like:

...

Showing status and information about "app_name":

...

urls: https://

You could get the URL of the application also from the command

xs apps

This command will list all applications in the current organization and space with their state and URLs.

Depending on your app you will also have to add the path to your servlet to the URL.

Best regards,

Nikolay

former_member250641
Participant
0 Kudos

Hi Nikolay ,

Thanks for your reply .

I have try both option you mention but not getting any result .

1)

2) For Manifest file , I have created a manifest file

5.png

but  when i try to push the code using  cmd

xs push -f manifest.yml


result

Please help me out if i am doing any wrong step here .

Thanks,

Sumit

Former Member
0 Kudos

Hi Sumit,

I think that I forgot to mention that you should replace the path/to/web/app/<name>.war with the actual path to the war file on your file system. I just gave it as an example, but it could be a relative or absolute path. For example /home/test/desktop/app/SignInProject.war or just ./SignInProject.war if the war file is in the same folder from where you execute xs push.

Best regards,

Nikolay

former_member250641
Participant
0 Kudos

Hi Nikolay ,

Thanks for your Reply .

But using manifest. its have some issue . saying that manifest.yml not finding ...

I have some question more ,

if i have some service which is made using Spring framework can we directly push and try to run on Hana or we need to do some modification .

Thanks,

Sumit

former_member250641
Participant
0 Kudos

When i Try to push the Java code which is written an Java Spring framework its return .

Former Member
0 Kudos

Hi Sumit,

Can you share your manifest.yml file.

There should be no issues to use spring framework in your application.

Best regards,

Nikolay

former_member250641
Participant
0 Kudos

Hi Nikolay ,

Thanks for your  support .

1) the manifest file for sample code  push

applications:

- name: test

  memory: 512m

  instance: 1

  path: /SignInProject.war

2) Now i am able to push my first web service but when i open the output url its showing me 503 error . but when i run the webservice  locally its running fine .

Thanks,

Sumit

Former Member
0 Kudos

Hi Sumit,

It looks like all files on the desktop are being pushed. Did you specify the path to the war file?

Best regards,

Nikolay

former_member250641
Participant
0 Kudos

Hi Nikolay ,

1) SignInProject.war is push and working fine in Hana but through Manifest.yml i m not able to push .


2) I have some Java service is written on java and usen Mavan Lib . When i run the service in locally using tomcat its run fine and give appropriate WSDL . now i am pushing the file using xs client tool and successfully uploaded    and give appropriate URL . but when i try to open its giving me 503 error .

3) I have some more question i am not created any mta.yaml  file or mtad.yaml . and when it mta.yaml  file or mtad.yaml need ed  for Java application can you please suggested .

Thanks,

Sumit

Former Member
0 Kudos

Hi Sumit,

Regarding 1. You could send me the manifest.yml file in order to check what is not working.

Regarding 2. Could you please send me the logs of the application. You could get them via the command "xs logs <app_name> --all"

Regarding 3. The mta archive and the mta.yaml file are used if you want to package several applications together. They mta archive has additional benefits, such as creation of service instances and binding them to application, configuring environment variables for applications, and etc. For more detailed information the developer quite is very useful: http://help.sap.com/hana/SAP_HANA_Developer_Guide_for_SAP_HANA_XS_Advanced_Model_en.pdf. If you want to deploy only one application, the is not required.

Best regards,

Nikolay

former_member250641
Participant
0 Kudos

Hi Nikolay ,

Thanks for your reply .

1) Now Manifest.yml file is working fine it was missing the path so that's  why it not working .

But after push the application when I open the URL  to  access the application it not asking me to Login authentication . What should i do for that ?

2) How to download the log file ?

Thanks ,

Sumit

Former Member
0 Kudos

Hi Sumit,

It is great that pushing you app with the manifest is also working. Regarding authentication. If you do not want to have an authentication for your application you have to make your resources public. To do that you have to open your web.xml file and remove the security constraints. Or if there are no security constraints, most likely you are using annotations to your servlet and you could remove them.

If you want your application to be protected it requires some additional steps:

  • Add an approuter
  • Create and bind a security service instance

I could send you more detailed explanation if it is needed.

In order to download the logs for your application, you could redirect them to a file:

xs logs <app_name> --all > logs.txt

Best regards,

Nikolay

former_member250641
Participant
0 Kudos

Hi Nikolay,

I want my application to be protected. you sad it requires some additional steps:

  • Add an approuter
  • Create and bind a security service instance

can you please suggest the step .

Thanks in advanced ..

Thank,

Sumit

Former Member
0 Kudos

Hi Sumit,

Please have a look at http://help.sap.com/hana/SAP_HANA_Developer_Guide_for_SAP_HANA_XS_Advanced_Model_en.pdf -> 6.2.1.4

If something is not clear, please let me know.

Best regards,

Nikolay

Former Member
0 Kudos

Hi Sumit,

With SPS12, HANA comes with XS Advanced, which offers a Java Runtime: Apache Tomcat or Apache TomEE. For more information regarding XS Advanced, please see

In order to run your Java code, you will have to create a Java EE web application. Internally we use maven to create our web applications. Here are some good articles that could help:

Connecting to HANA from within XS Advanced is quite easy and you even do not have to create the connection manually. For more information see the SAP HANA XS Advanced Developer Guide http://help.sap.com/hana/SAP_HANA_Developer_Guide_for_SAP_HANA_XS_Advanced_Model_en.pdf -> Configure Database Connection (page 487).

If you have any questions, please let me know.

Best regards,

Nikolay

former_member250641
Participant
0 Kudos

Hi Nikaloy ,

Thanks for your support .

But after connection what should i do for check my first java application run on SP 12 Hana

Thanks,

Sumit

Former Member
0 Kudos

Hi Sumit,

Were you able to push your java application to SAP HANA XS Advanced.

Did you use the xs CLI command?

Best regards,

Nikolau

former_member250641
Participant
0 Kudos

Hi Florian,

Thanks for your reply .

But i have one query regarding the server add on eclipse . which server i add to run the Java code . is it Locally install Apache tomcat or Hana . if  Hana what option need to be Put ?because

Thanks,

Sumit

pfefferf
Active Contributor
0 Kudos

To test your coding no server is needed.

If you wanna run it on a server you can use each local Java Server if the pre-conditions are fulfilled by your app.

The SAP HANA Cloud Platform option is for the usage of the Java App later on the SAP HANA Cloud Platform. From what you have written here and in your last posts, I don't think that is what you wanna do.

Regards,

Florian

pfefferf
Active Contributor
0 Kudos

Hello Sumit,

what is the question here, how you execute the program? If yes then you have different options to test/execute it.

E.g. if you use an IDE like Eclipse use the integrated "Run" functionality.

If you are a "hardcore" developer you can use also the command line. In the bin folder of the installed JDK you find the "javac.exe" (the Java Compiler) and the "java.exe" (the Java Interpreter). First you have to compile your ".java" file using "javac.exe". Then you can execute it using "java.exe" including the HANA JDBC driver (ngdbc.jar) with the classpath option (-cp).

Regards,

Florian