Skip to Content

how to create a JSP connection to SAP through Jco?

I want to create a JSP and fetch data from SAP. I followed the official tutorial of sJco 3.0 and stuck in the first step. I'm really confused. Can some give a hint ? below is the offical sample code.

public class StepByStepClient
{
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST,
"ls4065");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,
"85");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT,
"800");
connectProperties.setProperty(DestinationDataProvider.JCO_USER,
"homo faber");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD,
"alaska");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG,
"en");
createDestinationDataFile(DESTINATION_NAME1,
connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPA
CITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMI
T, "10");
createDestinationDataFile(DESTINATION_NAME2,
connectProperties);
}
static void createDestinationDataFile(String destinationName,
Properties connectProperties)
{
File destCfg = new File(destinationName+".jcoDestination");
try
{
FileOutputStream fos = new FileOutputStream(destCfg,
false);
connectProperties.store(fos, "for tests only !");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the
destination files", e);
}
}
public static void step1Connect() throws JCoException
  {
	  JCoDestination destination=JCoDestinationManager.getDestination(DESTINATION_NAME1);
	  System.out.print(destination.getAttributes());
  }

1.I don't understand what's the use of createDestinationDataFile method? It just create a file isn't it? all the property already set up in DestinationProvider, then why need a file?

2.I copy the sample code to a project and it worked. But when I triy to create a JSP and call it error happened. I doubt maybe the configuration file ABAP_AS_WITHOUT_POOL.property is the reason. Anyone has same error before? The error is below.

08:49:20,035 ERROR [stderr] (default task-2) java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path
08:49:20,036 ERROR [stderr] (default task-2) 	at java.lang.ClassLoader.loadLibrary(Unknown Source)
08:49:20,049 ERROR [stderr] (default task-2) 	at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
08:49:20,049 ERROR [stderr] (default task-2) 	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
08:49:20,186 ERROR [stderr] (default task-2) 	at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
08:49:20,187 ERROR [stderr] (default task-2) 	at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
...
08:49:20,229 ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /TestWebsite/1.jsp: javax.servlet.ServletException: java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path
	at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:889)
	at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:818)
	at org.apache.jsp._1_jsp._jspService(_1_jsp.java:165)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
	at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
	at io.undertow.jsp.JspFileHandler.handleRequest(JspFileHandler.java:32)
	at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
	...
Caused by: java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path
	at com.sap.conn.jco.rt.MiddlewareJavaRfc.<clinit>(MiddlewareJavaRfc.java:226)
	at com.sap.conn.jco.rt.DefaultJCoRuntime.initialize(DefaultJCoRuntime.java:98)
	at com.sap.conn.jco.rt.JCoRuntimeFactory.<clinit>(JCoRuntimeFactory.java:23)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at com.sap.conn.jco.JCo.createJCo(JCo.java:52)
	at com.sap.conn.jco.JCo.<clinit>(JCo.java:26)
	at com.sap.conn.jco.JCoDestinationManager.getDestination(JCoDestinationManager.java:104)
	at SCOfetch.JCOtest.step4QueryTable(JCOtest.java:217)
	at org.apache.jsp._1_jsp._jspService(_1_jsp.java:149)
	... 45 more
Add a comment
10|10000 characters needed characters exceeded

  • ricky luo, please follow up on your open question.

    • comment answers or your question if there are still open issues.
    • otherwise mark an answer as accepted if it helped you solve your problem
    • or post an answer of yourself and accept it if you found another useful solution yourself
    • or redirect your question to another question that is related and was useful to solve your problem
    • in the end, close your question

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on May 14 at 05:47 AM

    In wildfly 11 server. I create a module for the dll and jar in modules folder and in jboss-deployment-structure.xml point to it and problem solved.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 10 at 04:49 AM

    The sapjco3.dll seems to be missing or is the wrong version.

    Do you have the sapjco3.dll library installed and did you make sure that JVM and sapjco3.dll are for the same platform.

    Go to Start>Control Panel>Java to check JVM version.

    Otherwise try these links for more information:

    1. JCO 3 problems with Library - UnsatisfiedLinkError [SOLVED] - Toolbox for IT Groups

    2. https://scn.sap.com/thread/11967

    3. Error: sapJco3 load the Java library

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.