Hot Topic (More than 10 Replies) Strange behaviour with the Java API (Read 1734 times)
Juergen
Member
*
Offline



Posts: 9
Joined: Apr 28th, 2017
Strange behaviour with the Java API
May 22nd, 2017 at 4:36pm
Print Post Print Post  
Hello,

to have a workaround for a x64 python api I tried to use java (x86).

I have a application named klbindex.db. Within this application I have a db/form named songindex

I adjusted the given examples:

Code (Java)
Select All
public class main
{
	static
	{
		System.loadLibrary("sesame_java_api");
	}
	public static void main(String argv[])
	{
		if(sesame_java_api.SesameConnect("jpfg") > 0)
		{

			System.out.println("Connected");

			int rs = sesame_java_api.SesameSearch("klbindex.db", "songindex", 0, 2, "", "", "");

			System.out.printf("rs: %d\n", rs);

			if(rs > -1)
			{
				sesame_java_api.SesameClose(rs);
			}
			else
			{
				System.out.printf("Error: %d\n", sesame_java_api.SesameError() );
			}

			sesame_java_api.SesameDisconnect();
		}
	}
}
 



When I run it I get the following output:

Code
Select All
Connected
rs: -1
Error: 0
1
2
3
4
5
6
7 



In my understanding I should retrieve all existing records. The database is filled and has more than 0 records.

I can't explain the numbers 1 to 7. My code doesn't output the numbers

I use Sesame 2.6.3 Plus with the latest Sesame Api (2.6.2).

It would be nice if someone can give me a hint


Thanks
  

klbindex.png ( 1 KB | 92 Downloads )
klbindex.png
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Strange behaviour with the Java API
Reply #1 - May 22nd, 2017 at 4:46pm
Print Post Print Post  
What directory is klbindex.db located in?
What is the working directory of the Sesame Server?

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Juergen
Member
*
Offline



Posts: 9
Joined: Apr 28th, 2017
Re: Strange behaviour with the Java API
Reply #2 - May 22nd, 2017 at 5:04pm
Print Post Print Post  
klbindex.db is in /opt/Sesame2/Data

Working directory is /opt/Sesame2/


If I use the Sesame Plus Client - it works. So I guess that the Server setup is ok.
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Strange behaviour with the Java API
Reply #3 - May 22nd, 2017 at 5:22pm
Print Post Print Post  
The first argument to SesameSearch is either the full path or the relative path(Relative to the Server's working directory) to the application file. So you will want "Data/klbindex.db"

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Juergen
Member
*
Offline



Posts: 9
Joined: Apr 28th, 2017
Re: Strange behaviour with the Java API
Reply #4 - May 22nd, 2017 at 5:32pm
Print Post Print Post  
Cool!  Cool
That was it. Now I get the records

The numbers 1 to 7 are still printed. Don't know the meaning.

But now I can use the api.

Thank you very much.

Best regards
Jürgen

  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Strange behaviour with the Java API
Reply #5 - May 22nd, 2017 at 6:27pm
Print Post Print Post  
Juergen wrote on May 22nd, 2017 at 5:32pm:
The numbers 1 to 7 are still printed. Don't know the meaning.


I am unsure on that as well, as it does not occur when I compile and run the Java sample API code here.

Does it occur if you compile & run a simple 'Hello world' program?

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Juergen
Member
*
Offline



Posts: 9
Joined: Apr 28th, 2017
Re: Strange behaviour with the Java API
Reply #6 - May 22nd, 2017 at 6:58pm
Print Post Print Post  
When I simply build and run the following:

Code (Java)
Select All
if(sesame_java_api.SesameConnect("jpfg") > 0) {

            System.out.println("Connected");

            int rs = sesame_java_api.SesameSearch("Data/klbindex.db", "songindex", 0, 2, "!book=0", "", "");

            if (rs > -1) {
                int num = sesame_java_api.SesameTotal(rs);

                for (int loop = 1; loop <= num; loop++) {
                    sesame_java_api.SesameSetCurrentPosition(rs, loop);
                    String song = sesame_java_api.SesameGetValue(rs, "song");


                    System.out.println(song);
                }

                sesame_java_api.SesameClose(rs);
            } else {
                System.out.printf("Error: %d\n", sesame_java_api.SesameError());
            }

            sesame_java_api.SesameDisconnect(); 



it gives me the following output:

Code
Select All
/home/juergen/Programme/jdk1.8.0_131/bin/java -javaagent:/home/juergen/Programme/idea-IC-171.4424.56/lib/idea_rt.jar=60618:/home/juergen/Programme/idea-IC-171.4424.56/bin -Dfile.encoding=UTF-8 -classpath /home/juergen/Programme/jdk1.8.0_131/jre/lib/charsets.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/deploy.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/ext/cldrdata.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/ext/dnsns.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/ext/jaccess.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/ext/jfxrt.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/ext/localedata.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/ext/nashorn.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/ext/sunec.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/ext/sunjce_provider.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/ext/sunpkcs11.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/ext/zipfs.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/javaws.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/jce.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/jfr.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/jfxswt.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/jsse.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/management-agent.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/plugin.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/resources.jar:/home/juergen/Programme/jdk1.8.0_131/jre/lib/rt.jar:/home/juergen/IdeaProjects/GpxToSesame/out/production/GpxToSesame GpxToSesame
Connected
(Oh Baby Baby) It's A Wild World
Les Chemps-Elysées
O La Paloma Blanca
Ob-La-Di, Ob-La-Da
Obsesion
Ode To My Family
Oh Happy Day
Oh Pretty Woman
Oh Susanna
Oh Yeah
Ohne dich
Tramps & Thieves
1
2
3
4
5
6
7

Process finished with exit code 0 



As you can see in the above code I don't output numbers. They appear every time I execute the program.
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Strange behaviour with the Java API
Reply #7 - May 22nd, 2017 at 7:10pm
Print Post Print Post  
If you take out the Sesame API completely and simplify it down to just something as simple as Hello World, do you still get those numbers?

Code
Select All
public class HelloWorld {

    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
    }

} 

 

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Juergen
Member
*
Offline



Posts: 9
Joined: Apr 28th, 2017
Re: Strange behaviour with the Java API
Reply #8 - May 22nd, 2017 at 7:18pm
Print Post Print Post  
Code
Select All
public static void main(String argv[]) throws ParserConfigurationException, SAXException, IOException {

        System.out.println("Hello WOrld");

        /*
        if(sesame_java_api.SesameConnect("jpfg") > 0) {

            System.out.println("Connected");

            int rs = sesame_java_api.SesameSearch("Data/klbindex.db", "songindex", 0, 2, "!book=0", "", "");

            if (rs > -1) {
                int num = sesame_java_api.SesameTotal(rs);

                for (int loop = 1; loop <= num; loop++) {
                    sesame_java_api.SesameSetCurrentPosition(rs, loop);
                    String song = sesame_java_api.SesameGetValue(rs, "song");


                    System.out.println(song);
                }

                sesame_java_api.SesameClose(rs);
            } else {
                System.out.printf("Error: %d\n", sesame_java_api.SesameError());
            }

            sesame_java_api.SesameDisconnect();
        }*/
    } 



Output:
Code
Select All
Hello WOrld

Process finished with exit code 0
 

  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Strange behaviour with the Java API
Reply #9 - May 22nd, 2017 at 7:28pm
Print Post Print Post  
Okay now try a simple connect and disconnect and let me know the output.

Code
Select All
public class main
{
	static
	{
		System.loadLibrary("sesame_java_api");
	}
	public static void main(String argv[])
	{
		if(sesame_java_api.SesameConnect("jpfg") > 0)
		{

			System.out.println("Connected");
			sesame_java_api.SesameDisconnect();
			System.out.println("Disconnected");
		}
	}
} 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Juergen
Member
*
Offline



Posts: 9
Joined: Apr 28th, 2017
Re: Strange behaviour with the Java API
Reply #10 - May 22nd, 2017 at 7:37pm
Print Post Print Post  
Then the output:
Code
Select All
Connected
1
2
3
4
5
6
7
Disconnected

Process finished with exit code 0
 

  
Back to top
 
IP Logged