Hi Lourens,

The sample code looks correct and should retrieve the correct results if the data is loaded correctly into Virtuoso. Thus can you confirm the same query returns the correct results when executed via the Virtuoso isql command line program and the SPARQL endpoint (http://hostname:port/sparql ) ...

Best Regards
Hugh Williams
Professional Services
OpenLink Software
Web: http://www.openlinksw.com
Support: http://support.openlinksw.com
Forums: http://boards.openlinksw.com/support



On 18 Sep 2009, at 17:30, Lourens van der Meij wrote:

I tried getting RDF results of a query through JAVA. I used the
jdbc example occurring in the Virtuoso documentation, but Literals with
xml:lang specification return as java String.

The drivers I tested:
* recent virtjdbc3.jar (ftp'd just now)
 OpenLink Virtuoso(TM) Driver for JDBC(TM) Version 3.x [Build 3.35]
* The virtjdbc3.jar that came with the 6.0 windows binary installation:
 OpenLink Virtuoso(TM) Driver for JDBC(TM) Version 3.x [Build
3.27/06.00.3039]

 The virtuoso version is 6.0.0-pre2.3118-threads as of Apr 23 2009
(downloaded from virtuoso site)

 My query is:
"sparql SELECT ?l ?u where {?u skos:prefLabel
?l.FILTER(langmatches(lang(?l),\"nl\"))} LIMIT 10";

 I get results:
 "Populaire" genres en vormen
<http://www.oclc.org/nl/kar/Mp>

I did have to specify:-Djdbc.drivers=virtuoso.jdbc3.Driver in java as
otherwise
the driver was not found. The
Object o = ((VirtuosoResultSet)rs).getObject(i);
returns a java String for Literals, apparently even if the literal has
an xml:lang attribute.

Am I missing something?
Any advice? Should I use the higher level interfaces to java?

=================
The code:
import java.sql.*;
import virtuoso.jdbc3.*;

public class TestVirtuosoRDFBare {
   public static void main(String[] args) throws SQLException {
       String connectionURL =
"jdbc:virtuoso://localhost:1111/UID=demo/PWD=demo";
Connection connection = DriverManager.getConnection (connectionURL);
       Statement stmt = connection.createStatement();
       String query = "sparql SELECT ?l ?u where {?u skos:prefLabel
?l.FILTER(langmatches(lang(?l),\"nl\"))} LIMIT 10";
       boolean more = stmt.execute(query);
       ResultSetMetaData data = stmt.getResultSet().getMetaData();
       while (more) {
           ResultSet rs = stmt.getResultSet();
           while(rs.next()){
               for(int i = 1;i <= data.getColumnCount();i++) {
                   String s = rs.getString(i);
                   Object o = ((VirtuosoResultSet)rs).getObject(i);
                   if (o instanceof VirtuosoExtendedString) // String
representing an IRI
                   {
                       VirtuosoExtendedString vs =
(VirtuosoExtendedString) o;
                       if (vs.iriType == VirtuosoExtendedString.IRI)
                           System.out.println ("<" + vs.str +">");
else if (vs.iriType == VirtuosoExtendedString.BNODE)
                           System.out.println ("<" + vs.str +">");
                   }
else if (o instanceof VirtuosoRdfBox) // Typed literal
                   {
                       VirtuosoRdfBox rb = (VirtuosoRdfBox) o;
                       System.out.println (rb.rb_box + " lang=" +
rb.getLang() + " type=" + rb.getType());

                   }
                   else if(stmt.getResultSet().wasNull())
                       System.out.println("NULL");
                   else {
                       System.out.println(s);
                   }
               }
           }
           more = stmt.getMoreResults();
       }
       connection.close();
   }
}


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Virtuoso-users mailing list
Virtuoso-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtuoso-users


Reply via email to