Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 71d40963b505df4524269198e237b3e3 > files > 50

virtuoso-opensource-doc-6.1.4-2.fc14.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head profile="http://internetalchemy.org/2003/02/profile">
  <link rel="foaf" type="application/rdf+xml" title="FOAF" href="http://www.openlinksw.com/dataspace/uda/about.rdf" />
  <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
  <meta name="dc.title" content="7. Data Access Interfaces" />
  <meta name="dc.subject" content="7. Data Access Interfaces" />
  <meta name="dc.creator" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="dc.copyright" content="OpenLink Software, 1999 - 2009" />
  <link rel="top" href="index.html" title="OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="search" href="/doc/adv_search.vspx" title="Search OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="parent" href="accessinterfaces.html" title="Chapter Contents" />
  <link rel="prev" href="odbcimplementation.html" title="Virtuoso Driver for ODBC" />
  <link rel="next" href="virtoledb.html" title="OLE DB Provider for Virtuoso" />
  <link rel="shortcut icon" href="../images/misc/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" type="text/css" href="doc.css" />
  <link rel="stylesheet" type="text/css" href="/doc/translation.css" />
  <title>7. Data Access Interfaces</title>
  <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
  <meta name="author" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="copyright" content="OpenLink Software, 1999 - 2009" />
  <meta name="keywords" content="" />
  <meta name="GENERATOR" content="OpenLink XSLT Team" />
 </head>
 <body>
  <div id="header">
    <a name="VirtuosoDriverJDBC" />
    <img src="../images/misc/logo.jpg" alt="" />
    <h1>7. Data Access Interfaces</h1>
  </div>
  <div id="navbartop">
   <div>
      <a class="link" href="accessinterfaces.html">Chapter Contents</a> | <a class="link" href="odbcimplementation.html" title="Virtuoso Driver for ODBC">Prev</a> | <a class="link" href="virtoledb.html" title="OLE DB Provider for Virtuoso">Next</a>
   </div>
  </div>
  <div id="currenttoc">
   <form method="post" action="/doc/adv_search.vspx">
    <div class="search">Keyword Search: <br />
        <input type="text" name="q" /> <input type="submit" name="go" value="Go" />
    </div>
   </form>
   <div>
      <a href="http://www.openlinksw.com/">www.openlinksw.com</a>
   </div>
   <div>
      <a href="http://docs.openlinksw.com/">docs.openlinksw.com</a>
   </div>
    <br />
   <div>
      <a href="index.html">Book Home</a>
   </div>
    <br />
   <div>
      <a href="contents.html">Contents</a>
   </div>
   <div>
      <a href="preface.html">Preface</a>
   </div>
    <br />
   <div class="selected">
      <a href="accessinterfaces.html">Data Access Interfaces</a>
   </div>
    <br />
   <div>
      <a href="virtclientref.html">ADO.Net Data Provider</a>
   </div>
   <div>
      <a href="isql.html">Interactive SQL Utility</a>
   </div>
   <div>
      <a href="odbcimplementation.html">Virtuoso Driver for ODBC</a>
   </div>
   <div class="selected">
      <a href="VirtuosoDriverJDBC.html">Virtuoso Driver for JDBC</a>
    <div>
        <a href="#VirtuosoDriverPackaging" title="Virtuoso Drivers for JDBC Packaging">Virtuoso Drivers for JDBC Packaging</a>
        <a href="#jdbcurl4mat" title="Virtuoso Driver For JDBC URL Format">Virtuoso Driver For JDBC URL Format</a>
        <a href="#jdbc3features" title="Virtuoso Driver JDBC 3.0 features">Virtuoso Driver JDBC 3.0 features</a>
        <a href="#jdbc4features" title="Virtuoso Driver JDBC 4.0 features">Virtuoso Driver JDBC 4.0 features</a>
        <a href="#JDBCDriverInstallConfig" title="Installation &amp; Configuration Steps">Installation &amp; Configuration Steps</a>
        <a href="#JDBCDriverhibernate" title="Virtuoso JDBC Driver Hibernate Support">Virtuoso JDBC Driver Hibernate Support</a>
    </div>
   </div>
   <div>
      <a href="virtoledb.html">OLE DB Provider for Virtuoso</a>
   </div>
   <div>
      <a href="inprocess.html">Virtuoso In-Process Client</a>
   </div>
   <div>
      <a href="accintudsockets.html">Unix Domain Socket Connections</a>
   </div>
   <div>
      <a href="dataccessclientsconfailandbalance.html">Virtuoso Data Access Clients Connection Fail over and Load Balancing Support</a>
   </div>
    <br />
  </div>
  <div id="text">
    <a name="VirtuosoDriverJDBC" />
    <h2>7.4. Virtuoso Driver for JDBC</h2>
				<p>The Virtuoso Drivers for JDBC are available in
   &quot;jar&quot; file formats for JDBC 1.x,  JDBC 2.x and JDBC 3.x specifications. These
    are Type 4 Drivers implying that utilization is simply a case of adding the relevant
    &quot;jar&quot; file to your CLASSPATH and then providing an appropriate JDBC URL format
    in order to establish a JDBC session with a local or remote Virtuoso server. It is
    important to note that when you make a JDBC connection to a Virtuoso Server, you do also
    have access to Native and External Virtuoso tables. Thus, you actually have a type 4 JDBC
    Driver for any number of different database types that have been linked into Virtuoso.</p>
    <p>The JDBC 2 and JDBC 3 drivers also incorporate SSL encryption to enable very secure connections
    to the Virtuoso database.</p>
				
					<a name="VirtuosoDriverPackaging" />
    <h3>7.4.1. Virtuoso Drivers for JDBC Packaging</h3>
					<p>These drivers are installed alongside the Virtuoso Server
    or as part of a Virtuoso Client components only installation.
    They are packaged as follows:</p>
					<table class="data">
						<caption>Table: 7.4.1.1. Features Comparison</caption>
						
							
							
								<tr>
									<th class="data">Driver Name</th>
									<th class="data">Java Package</th>
									<th class="data">&quot;jar&quot; File Archive</th>
									<th class="data">Default Location</th>
									<th class="data">Java  Version</th>
								</tr>
							
							
								<tr>
									<td class="data">virtuoso.jdbc.Driver</td>
									<td class="data">virtuoso.jdbc</td>
									<td class="data">virtjdbc.jar</td>
									<td class="data">&lt;virtuoso installation directory&gt;\jdk11</td>
									<td class="data">Java 1.1.x</td>
								</tr>
								<tr>
									<td class="data">virtuoso.jdbc2.Driver</td>
									<td class="data">virtuoso.jdbc2</td>
									<td class="data">virtjdbc2.jar</td>
									<td class="data">&lt;virtuoso installation directory&gt;\jdk12</td>
									<td class="data">Java 1.2/1.3</td>
								</tr>
								<tr>
									<td class="data">virtuoso.jdbc3.Driver used for Java 1.4 and Java 1.5</td>
									<td class="data">virtuoso.jdbc3</td>
									<td class="data">virtjdbc3.jar</td>
									<td class="data">&lt;virtuoso installation directory&gt;\jdk13</td>
									<td class="data">Java 1.4</td>
								</tr>
								<tr>
									<td class="data">virtuoso.jdbc4.Driver used for Java 1.6</td>
									<td class="data">virtuoso.jdbc4</td>
									<td class="data">virtjdbc4.jar</td>
									<td class="data">&lt;virtuoso installation directory&gt;\jdk14</td>
									<td class="data">Java 1.6</td>
								</tr>

							
						
					</table>
    <br />
				<br />
				
					<a name="jdbcurl4mat" />
    <h3>7.4.2. Virtuoso Driver For JDBC URL Format</h3>
					<p>JDBC compliant applications and applets connect to JDBC
    Drivers using JDBC Uniform Resource Locators (URLs). Although there are two Virtuoso
    Drivers for JDBC, both share the same JDBC URL format. </p>
					<p>The Virtuoso Driver for JDBC URL format takes the
    following form:</p>
					<div>
      <pre class="programlisting">
jdbc:virtuoso://&lt;Hostname&gt;:&lt;Port#&gt;/DATABASE=&lt;dbname&gt;/UID=&lt;user name&gt;/PWD=&lt;password&gt;/
  CERT=&lt;certificate_alias&gt;/KPATH=&lt;keystore_path&gt;/PASS=&lt;keystore_password&gt;/
  PROVIDER=&lt;ssl_provider_classname&gt;/SSL/CHARSET=&lt;character set&gt;/
  TIMEOUT=&lt;timeout_secs&gt;/PWDTYPE=&lt;authentication_type&gt;/log_enable=&lt;integer&gt;
</pre>
    </div>
<p>
Also is supported Host:Port list in connection string:
</p>
<div>
      <pre class="programlisting">
jdbc:virtuoso://&lt;Hostname&gt;:&lt;Port#&gt;,&lt;Hostname1&gt;:&lt;Port1#&gt;,&lt;Hostname2&gt;:&lt;Port2#&gt;/
</pre>
    </div>
<p>
If Port is omitted, the default port 1111 is used.
</p>

					<p>Each part of the URL is explained
       					below:</p> <div class="formalpara">
						<strong>Protocol Identifiers</strong>
   					<p>this is a constant value of
   					&quot;jdbc&quot; since JDBC is the
      					protocol in question</p>
 					</div> <div class="formalpara"> <strong>Sub
 					Protocol Identifier</strong> <p>this
  					is a constant value that identifies
 					&quot;virtuoso&quot; as a sub protocol
      					of JDBC</p> </div>
  					<div class="formalpara"> <strong>Hostname</strong>
						<p>this identifies the machine
					hosting a server process that speaks the
					&quot;virtuoso&quot; sub dialect of the
    &quot;jdbc&quot; protocol</p>
 					</div> <div class="formalpara"> <strong>Port
					Number</strong> <p>this identifies the
 					port number on the machine from which
      					the server which speaks the
  					&quot;virtuoso&quot; sub dialect of
					&quot;jdbc&quot; listening for incoming
  					client connections The default port
    					number for a Virtuoso server is
 					&quot;1111&quot;.</p> </div>
 					<div class="formalpara"> <strong>/DATABASE</strong>
						<p>this identifies the database
  					(Qualifier or Catalog) that you are
      					connecting to via a Virtuoso
					server</p> </div> <div class="formalpara">
 					<strong>/UID</strong> <p>a valid user
					name for the Virtuoso database that you
   					are connecting to via JDBC</p>
       					</div> <div class="formalpara">
   					<strong>/PWD</strong> <p>a valid
   					password for the user name </p>
             					</div>
					<div class="formalpara">
      <strong>/CERT=&lt;certificate
  					_alias&gt;</strong> <p>name of the
     					certificate to use for the SSL
					connection stored in the keystore. This
    					is a required option for an SSL
    					authenticated connection</p>
             					</div>
					<div class="formalpara">
      <strong>/KPATH=&lt;keystore_p
  					ath&gt;</strong> <p>This optional
					parameter lets you specify the keystore
 					file name (default: $HOME/.keystore).
 					The path separator is \, and which is
 					then replaced during the connection by
        					the right platform path
    					separator.</p> </div>
					<div class="formalpara">
      <strong>/PASS=&lt;keystore_pa
   					ssword&gt;</strong> <p>password
  					required for accessing the keystore
  					file.  This is required for the SSL
    					authenticated connection.</p>
             					</div>
					<div class="formalpara">
      <strong>/PROVIDER=&lt;ssl_pro
 					vider_classname&gt;</strong> <p>The
  					class name of the SSL Provider (e.g.
 					com.sun.ssl.net.internal.ssl.Provider)
 					to use for the SSL cryptography.  This
     					parameter is required for SSL
   					connections.</p> </div>
  <div class="formalpara">
      <strong>/SSL</strong>
 					<p>The SSL option is used only for
      					SSL connection without user
  					authentication</p> </div>
					<div class="formalpara">
      <strong>/CHARSET=&lt;characte
					r set&gt;</strong> <p>This allows the
 					client to specify a character set for
 					data encoding. When this option is set
					then all Java strings, natively Unicode,
   					are converted to the character set
  					specified here.</p> </div>
					<div class="formalpara">
      <strong>/TIMEOUT=&lt;timeout_
  					secs&gt;</strong> <p>Specifies the
					maximum amount of time (in seconds) that
					the driver will wait for a response to a
  					query.  When this time is exceeded a
					time-out error will be reported and the
					network connection closed, assumed to be
      					broken.</p> </div>
					<div class="formalpara">
      <strong>/PWDCLEAR=&lt;authent
					ication_type&gt;</strong> <p>Specifies
 					the authentication mode; how the user
 					credentials may be transmitted to the
 					server.  This option can be one of the
 					following 3 types: cleartext, encrypt,
 					digest. The default is digest.</p>
                                        <p>&quot;cleartext&quot; will transfer the
       					password to the server in
 					cleartext</p> <p>&quot;encrypt&quot; will
  					transfer the password to the server
 					using Virtuoso&#39;s symmetric encryption
 					technique.</p> <p>&quot;digest&quot; will
					calculate an MD5 digest of the password
					(and some additional session variables)
 					that will be sent to the server to be
   					compared with the value calculated
          					server-side.</p>
             					</div>
					<div class="formalpara">
      <strong>/log_enable=&lt;integ
					er&gt;</strong> <p>Set log_enable=2 in
 					order to auto commit on every changed
 					row. Out of memory cannot be caused as
 					with this setting there is no image in
    					the memory for rollback.</p>
             					</div>
 					<div class="formalpara">
      <strong>/roundrobin</strong>
 					<p>boolean attribute  1 -  for use
					RoundRobin; 0 -  do not use . (used only
					if more than one host:post values are in
					connection string)</p> </div>
    					<div class="formalpara">
      <strong>/fbs</strong>
					<p>integer attribute, prefetch buffer
      					size (default is 100)</p>
             					</div>
   					<div class="formalpara">
      <strong>/sendbs</strong>
  					<p>integer attribute, socket send
     					buffer size (default is 32768
      					bytes)</p> </div>
   					<div class="formalpara">
      <strong>/recvbs</strong>
					<p>integer attribute, socket receive
     					buffer size (default is 32768
      					bytes)</p> </div>
					<div class="formalpara">
      <strong>/usepstmtpool</strong>
 					<p>boolean attribute  1 -  for use
					PreparedStatement pool; 0 -  do not use
  					(Only for Java 1.6 and above)</p>
             					</div>
					<div class="formalpara">
      <strong>/pstmtpoolsize</strong>
        					<p>integer attribute,
					PreparedStatement pool size (default is
        					25)</p> </div>


<div class="note">
      <div class="notetitle">Note:</div>
<p>Since JSSE has only incorporated SSL support for JDK 1.2 and above,
SSL has only been implemented for the JDBC 2.x, JDBC 3.x and JDBC 4.x drivers for Virtuoso.</p>
</div>

				<br />
    <a name="jdbc3features" />
    <h3>7.4.3. Virtuoso Driver JDBC 3.0 features</h3>
				
					<a name="jdbc3dsprops" />
    <h4>7.4.3.1. Virtuoso Driver For JDBC 3.0 javax.sql.DataSource</h4>
					<p>JDBC 3.0 compliant applications and applets may connect to a JDBC
    data source using JDBC <span class="computeroutput">javax.sql.DataSource</span> instances. 
    The Virtuoso JDBC 3.0 driver provides an implementation of the 
    <span class="computeroutput">javax.sql.DataSource</span> interface in the 
    <span class="computeroutput">virtuoso.jdbc3.VirtuosoDataSource</span> class, 
    supporting the following properties:</p>

					<table class="data">
						<caption>Table: 7.4.3.1.1. JDBC 3.0 VirtuosoDataSource properties</caption>
						
							
							
								<tr>
									<th class="data">Name</th>
									<th class="data">Type</th>
									<th class="data">URL Option Equivalent</th>
									<th class="data">Description</th>
								</tr>
							
							
								<tr>
									<td class="data">dataSourceName</td>
									<td class="data">java.lang.String</td>
									<td class="data" />
									<td class="data">used in connection pooling</td>
								</tr>
								<tr>
									<td class="data">description</td>
									<td class="data">java.lang.String</td>
									<td class="data" />
									<td class="data">string to describe the data source (free form)</td>
								</tr>
								<tr>
									<td class="data">serverName</td>
									<td class="data">java.lang.String</td>
									<td class="data" />
									<td class="data">The host name of the remote host to connect to</td>
								</tr>
								<tr>
									<td class="data">portNumber</td>
									<td class="data">int</td>
									<td class="data" />
									<td class="data">The port on the remote host to connect to</td>
								</tr>
								<tr>
									<td class="data">user</td>
									<td class="data">java.lang.String</td>
									<td class="data">/UID</td>
									<td class="data">username to use for the session</td>
								</tr>
								<tr>
									<td class="data">password</td>
									<td class="data">java.lang.String</td>
									<td class="data">/PWD</td>
									<td class="data">password to use for the session</td>
								</tr>
								<tr>
									<td class="data">databaseName</td>
									<td class="data">java.lang.String</td>
									<td class="data">/DATABASE</td>
									<td class="data">Initial catalog qualifier for the session</td>
								</tr>
								<tr>
									<td class="data">charset</td>
									<td class="data">java.lang.String</td>
									<td class="data">/CHARSET</td>
									<td class="data">Charset used in wide&lt;-&gt;narrow translations</td>
								</tr>
								<tr>
									<td class="data">pwdClear</td>
									<td class="data">java.lang.String</td>
									<td class="data">/PWDTYPE</td>
									<td class="data">authentication method</td>
								</tr>
							
						
					</table>
    <br />
				<br />
				
					<a name="jdbcdspool" />
    <h4>7.4.3.2. Virtuoso Driver For JDBC 3.0 &amp; Connection Pooling</h4>
					<p>The Virtuoso JDBC 3.0 driver supports connection pooling.</p>
  <p>The virtuoso.jdbc3.VirtuosoDataSource implements the 
  <span class="computeroutput">javax.sql.ConnectionPoolDataSource</span> 
  interface.  In order to use the connection pooling the administrator must deploy 
  one instance of the <span class="computeroutput">virtuoso.jdbc3.VirtuosoDriver</span> 
  in the JNDI repository and set all of it&#39;s properties except <span class="computeroutput">dataSourceName</span>. 
  This is the &quot;main&quot; connection pooling data source. Then the administrator should 
  deploy a second instance of the <span class="computeroutput">virtuoso.jdbc3.VirtuosoDataSource</span> 
  class and set only it&#39;s <span class="computeroutput">dataSourceName</span> property.</p>
  <p>Applications will use the second <span class="computeroutput">virtuoso.jdbc3.VirtuosoDataSource</span> 
  instance to get a connection. It will in turn call the first one to obtain all connect 
  info and return the <span class="computeroutput">java.sql.Connection</span> 
  instance.</p>
				<br />
				
					<a name="jdbcxa" />
    <h4>7.4.3.3. Virtuoso Driver For JDBC 3.0 &amp; Distributed Transactions</h4>
					<p>Virtuoso supports the industry
standard XA specification for distributed transaction processing. The XA
specification defines an interface between the transaction manager (TM) and
resource manager (RM) in a distributed transaction system. This is a generic
interface and it does not directly address the use of distributed transactions
from Java. The Java mapping of the XA interface is defined in Sun Microsystems
Java Transaction API (JTA) and JDBC 3.0 specifications. The Virtuoso JDBC 3.0
driver supports the JTA architecture by providing the implementation of JTA
resource manager interfaces.</p>
					<p>The Virtuoso JDBC 3.0 driver
provides the <span class="computeroutput">virtuoso.java3.VirtuosoXid</span>,
<span class="computeroutput">virtuoso.java3.VirtuosoXADataSource</span>,
<span class="computeroutput">virtuoso.java3.VirtuosoXAConnection</span>, and
<span class="computeroutput">virtuoso.java3.VirtuosoXAResource</span> classes
which implement the interfaces
<span class="computeroutput">javax.transaction.xa.Xid</span>,
<span class="computeroutput">javax.transaction.xa.XADataSource</span>,
<span class="computeroutput">javax.sql.XAConnection</span>, and
<span class="computeroutput">javax.sql.XAResource</span> respectively.
The use if these interfaces is usually transparent for applications and the
application developer shouldn&#39;t bother with them. They are used only by
the JTS transaction manager which normally runs as a part of the J2EE
server.</p>
					<p>The task of the J2EE server
administrator is to setup the necessary Virtuoso XA datasources. The exact
procedure of this depends on the J2EE server in use (such as BEA WebLogic,
IBM WebSphere, etc). Generally, this includes two steps:</p>
					<ol>
      <li>
						<p>Include the JDBC driver&#39;s
jar file into J2EE server&#39;s class path.</p>
					    </li>
      <li>
						<p>Deploy an instance of
<span class="computeroutput">javax.transaction.xa.XADataSource</span> with
appropriately set properties into the J2EE server&#39;s JNDI repository.</p>
					    </li>
    </ol>
					<p>
The <span class="computeroutput">virtuoso.java3.VirtuosoXADataSource</span> class
is derived from <span class="computeroutput">virtuoso.java3.VirtuosoDataSource</span>
and inherits all of its properties. These properties has to be set as described
in the section <a href="VirtuosoDriverJDBC.html#jdbc3dsprops">Virtuoso Driver For JDBC 3.0 javax.sql.DataSource</a>.</p>
					<p>For example, the following has to
be done in case of Sun&#39;s J2EE Reference Implementation.</p>
					<ol>
      <li>
						<p>Add the path of
virtjdbc3.jar to the J2EE_CLASSPATH variable in the file
$(J2EE_HOME)/bin/userconfig.bat on Windows or $(J2EE_HOME)/bin/userconfig.sh on
Unix/Linux:</p>
<div>
          <pre class="programlisting">
    set J2EE_CLASSPATH=C:/Virtuoso/lib/virtjdbc3.jar
</pre>
        </div>
or
<div>
          <pre class="programlisting">
    J2EE_CLASSPATH=/home/login/virtuoso/lib/virtjdbc3.jar
    export J2EE_CLASSPATH
</pre>
        </div>
					    </li>
      <li>
						<p>Using the following
command add the XA datasource with JNDI name &quot;jdbc/Virtuoso&quot; which refers to
the Virtuoso server running on the same computer on port 1111:</p>
<div>
          <pre class="programlisting">
    j2eeadmin -addJdbcXADatasource jdbc/Virtuoso virtuoso.jdbc3.VirtuosoXADataSource -props serverName=localhost portNumber=1111
</pre>
        </div>
					    </li>
    </ol>
				<br />
				
					<a name="jdbcrs" />
    <h4>7.4.3.4. JDBC 3.0 javax.sql.RowSet Driver Implementation</h4>
					<p>The Virtuoso JDBC 3.0 driver has two implementations of the 
          <span class="computeroutput">javax.sql.RowSet</span> interface - 
          <span class="computeroutput">virtuoso.javax.OPLCachedRowSet</span> and 
          <span class="computeroutput">virtuoso.javax.OPLJdbcRowSet</span>.</p>
          <p>The <span class="computeroutput">virtuoso.javax.OPLCachedRowSet</span> 
          class implements a totally disconnected, memory cached rowset and the 
          <span class="computeroutput">virtuoso.javax.OPLJdbcRowset</span> class 
          spans the rest of the JDBC API to implement it&#39;s methods.</p>
				<br />
  
      <a name="jdbcrdf" />
    <h4>7.4.3.5. Extension datatype for RDF</h4>
      <p>The IRIs and RDF literals, kept in the Virtuoso RDF store are represented by a strings and structures. Thus accessing RDF objects needs special datatypes in order to distinguish strings from IRIs and to get language and datatype of the RDF literals.</p>
      <p>Therefore Virtuoso JDBC driver provides following classes for accessing RDF store: <span class="computeroutput">virtuoso.jdbc3.VirtuosoExtendedString</span> for IRIs and <span class="computeroutput">virtuoso.jdbc3.VirtuosoRdfBox</span> for RDF literal objects.</p>
      <p>
	  The class <span class="computeroutput">virtuoso.jdbc3.VirtuosoExtendedString</span> will be returned when a string representing an IRI is returned to the client. It has two members &quot;str&quot; and &quot;iriType&quot;, the &quot;str&quot; member keeps string representation of the IRI, &quot;iriType&quot; denote regular IRI or blank node with enum values VirtuosoExtendedString.IRI and VirtuosoExtendedString.BNODE. 
      </p>
      <p>
	  If the RDF literal object have language or datatype specified then <span class="computeroutput">virtuoso.jdbc3.VirtuosoRdfBox</span> will be returned. The following methods could be used :
      </p>
      <div>
      <pre class="programlisting">
	  String toString () : returns string representation of the literal
	  String getType () : returns string containing the datatype  of the literal
	  String getLang () : returns language code for the literal
      </pre>
    </div>
      <p>
	  The following code snippet demonstrates how to use extension datatypes for RDF
      </p>
      <div>
      <pre class="programlisting">
    ... initialization etc. skipped for brevity 
    boolean more = stmt.execute(&quot;sparql select * from &lt;gr&gt; where { ?x ?y ?z }&quot;);
    ResultSetMetaData data = stmt.getResultSet().getMetaData();
    while(more)
    {
	rs = stmt.getResultSet();
	while(rs.next())
	{
	    for(int i = 1;i &lt;= 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 &amp;&amp; (vs.strType &amp; 0x01) == 0x01)
			System.out.println (&quot;&lt;&quot; + vs.str +&quot;&gt;&quot;);  
		    else if (vs.iriType == VirtuosoExtendedString.BNODE)
			System.out.println (&quot;&lt;&quot; + vs.str +&quot;&gt;&quot;);  
		  }  
		else if (o instanceof VirtuosoRdfBox) // Typed literal
		  { 
		    VirtuosoRdfBox rb = (VirtuosoRdfBox) o;
		    System.out.println (rb.rb_box + &quot; lang=&quot; + rb.getLang() + &quot; type=&quot; + rb.getType());
		    
		  }	      
		else if(stmt.getResultSet().wasNull())
		    System.out.println(&quot;NULL&quot;);
		else //  
		{
		    System.out.println(s);
		}
		    
	    }
	}
	more = stmt.getMoreResults();
    }
    ...
	    </pre>
    </div>
  <br />
                                <br />
<a name="jdbc4features" />
    <h3>7.4.4. Virtuoso Driver JDBC 4.0 features</h3>
				
					<a name="jdbc4dsprops" />
    <h4>7.4.4.1. Virtuoso Driver For JDBC 4.0 javax.sql.DataSource</h4>
					<p>JDBC 4.0 compliant applications and applets may connect to a JDBC
    data source using JDBC <span class="computeroutput">javax.sql.DataSource</span> instances.
    The Virtuoso JDBC 4.0 driver provides an implementation of the
    <span class="computeroutput">javax.sql.DataSource</span> interface in the
    <span class="computeroutput">virtuoso.jdbc4.VirtuosoDataSource</span> class,
    supporting the following properties:</p>

					<table class="data">
						<caption>Table: 7.4.4.1.1. JDBC 4.0 VirtuosoDataSource properties</caption>
						
							
							
								<tr>
									<th class="data">Name</th>
									<th class="data">Type</th>
									<th class="data">URL Option Equivalent</th>
									<th class="data">Description</th>
								</tr>
							
							
								<tr>
									<td class="data">dataSourceName</td>
									<td class="data">java.lang.String</td>
									<td class="data" />
									<td class="data">used in connection pooling</td>
								</tr>
								<tr>
									<td class="data">description</td>
									<td class="data">java.lang.String</td>
									<td class="data" />
									<td class="data">string to describe the data source (free form)</td>
								</tr>
								<tr>
									<td class="data">serverName</td>
									<td class="data">java.lang.String</td>
									<td class="data" />
									<td class="data">The host name of the remote host to connect to</td>
								</tr>
								<tr>
									<td class="data">portNumber</td>
									<td class="data">int</td>
									<td class="data" />
									<td class="data">The port on the remote host to connect to</td>
								</tr>
								<tr>
									<td class="data">user</td>
									<td class="data">java.lang.String</td>
									<td class="data">/UID</td>
									<td class="data">username to use for the session</td>
								</tr>
								<tr>
									<td class="data">password</td>
									<td class="data">java.lang.String</td>
									<td class="data">/PWD</td>
									<td class="data">password to use for the session</td>
								</tr>
								<tr>
									<td class="data">databaseName</td>
									<td class="data">java.lang.String</td>
									<td class="data">/DATABASE</td>
									<td class="data">Initial catalog qualifier for the session</td>
								</tr>
								<tr>
									<td class="data">charset</td>
									<td class="data">java.lang.String</td>
									<td class="data">/CHARSET</td>
									<td class="data">Charset used in wide&lt;-&gt;narrow translations</td>
								</tr>
								<tr>
									<td class="data">pwdClear</td>
									<td class="data">java.lang.String</td>
									<td class="data">/PWDTYPE</td>
									<td class="data">authentication method</td>
								</tr>
							
						
					</table>
    <br />
<p>Additionally, the following attributres are supported:</p>
<div>
      <pre class="programlisting">

--- for SSL enabled ---
   public void setCertificate (String value);
   public String getCertificate ();

   public void setKeystorepass (String value);
   public String getKeystorepass ();

   public void setKeystorepath (String value);
   public String getKeystorepath ();

   public void setProvider (String value);
   public String getProvider ();

----------------------

   public void setFbs (int value);
   public int getFbs ();

   public void setSendbs (int value);
   public int getSendbs ();

   public void setRecvbs (int value);
   public int getRecvbs ();

   public void setRoundrobin (boolean value);
   public boolean getRoundrobin ();

-- For Java 1.6 and above
   public void setUsepstmtpool (boolean value);
   public boolean getUsepstmtpool ();

   public void setPstmtpoolsize (int value);
   public int getPstmtpoolsize ();

</pre>
    </div>
				<br />
				
					<a name="jdbcdspool4" />
    <h4>7.4.4.2. Virtuoso Driver For JDBC 4.0 &amp; Connection Pooling</h4>
					<p>The Virtuoso JDBC 4.0 driver supports connection pooling.</p>
  <p>The virtuoso.jdbc4.VirtuosoDataSource implements the
  <span class="computeroutput">javax.sql.ConnectionPoolDataSource</span>
  interface.  In order to use the connection pooling the administrator must deploy
  one instance of the <span class="computeroutput">virtuoso.jdbc4.VirtuosoDriver</span>
  in the JNDI repository and set all of it&#39;s properties except <span class="computeroutput">dataSourceName</span>.
  This is the &quot;main&quot; connection pooling data source. Then the administrator should
  deploy a second instance of the <span class="computeroutput">virtuoso.jdbc4.VirtuosoDataSource</span>
  class and set only it&#39;s <span class="computeroutput">dataSourceName</span> property.</p>
  <p>Applications will use the second <span class="computeroutput">virtuoso.jdbc4.VirtuosoDataSource</span>
  instance to get a connection. It will in turn call the first one to obtain all connect
  info and return the <span class="computeroutput">java.sql.Connection</span>
  instance.</p>
  <p>VirtuosoConnectionPoolDataSource.class has the following connection pooling attributes:</p>
<div>
      <pre class="programlisting">
/**
 * Get the minimum number of physical connections
 * the pool will keep available at all times. Zero ( 0 ) indicates that
 * connections will be created as needed.
 *
 * @return   the minimum number of physical connections
 *
**/
public int getMinPoolSize();

/**
 * Set the number of physical connections the pool should keep available
 * at all times. Zero ( 0 ) indicates that connections should be created
 * as needed
 * The default value is 0 .
 *
 * @param   parm a minimum number of physical connections
 *
 * @exception  java.sql.SQLException if an error occurs
 *
**/

public void setMinPoolSize(int parm);



/**
 * Get the maximum number of physical connections
 * the pool will be able contain. Zero ( 0 ) indicates no maximum size.
 *
 * @return   the maximum number of physical connections
 *
**/
public int getMaxPoolSize();

/**
 * Set the maximum number of physical conections that the pool should contain.
 * Zero ( 0 ) indicates no maximum size.
 * The default value is 0 .
 *
 * @param   parm a maximum number of physical connections
 *
 * @exception  java.sql.SQLException if an error occurs
 *
**/
public void setMaxPoolSize(int parm);


/**
 * Get the number of physical connections the pool
 * will contain when it is created
 *
 * @return   the number of physical connections
 *
**/
public int getInitialPoolSize();

/**
 * Set the number of physical connections the pool
 * should contain when it is created
 *
 * @param   parm a number of physical connections
 *
 * @exception  java.sql.SQLException if an error occurs
 *
**/
public void setInitialPoolSize(int parm);

/**
 * Get the number of seconds that a physical connection
 * will remain unused in the pool before the
 * connection is closed. Zero ( 0 ) indicates no limit.
 *
 * @return   the number of seconds
**/
public int getMaxIdleTime();

/**
 * Set the number of seconds that a physical connection
 * should remain unused in the pool before the
 * connection is closed. Zero ( 0 ) indicates no limit.
 *
 * @param  parm a number of seconds
 *
 * @exception  java.sql.SQLException if an error occurs
 *
**/
public void setMaxIdleTime(int parm);

/**
 * Get the interval, in seconds, that the pool will wait
 * before enforcing the current policy defined by the
 * values of the above connection pool properties
 *
 * @return  the interval (in seconds)
**/
public int getPropertyCycle();

/**
 * Set the interval, in seconds, that the pool should wait
 * before enforcing the current policy defined by the
 * values of the above connection pool properties
 *
 * @param  parm an interval (in seconds)
**/
public void setPropertyCycle(int parm);


/**
 * Get the total number of statements that the pool will
 * keep open. Zero ( 0 ) indicates that caching of
 * statements is disabled.
 *
 * @return  the total number of statements
**/
public int getMaxStatements();

/**
 * Set the total number of statements that the pool should
 * keep open. Zero ( 0 ) indicates that caching of
 * statements is disabled.
 *
 * @param  parm a total number of statements
 *
 * @exception  java.sql.SQLException if an error occurs
 *
**/
public void setMaxStatements(int parm);

</pre>
    </div>

				<br />
				
					<a name="jdbcxa4" />
    <h4>7.4.4.3. Virtuoso Driver For JDBC 4.0 &amp; Distributed Transactions</h4>
					<p>Virtuoso supports the industry
standard XA specification for distributed transaction processing. The XA
specification defines an interface between the transaction manager (TM) and
resource manager (RM) in a distributed transaction system. This is a generic
interface and it does not directly address the use of distributed transactions
from Java. The Java mapping of the XA interface is defined in Sun Microsystems
Java Transaction API (JTA) and JDBC 4.0 specifications. The Virtuoso JDBC 4.0
driver supports the JTA architecture by providing the implementation of JTA
resource manager interfaces.</p>
					<p>The Virtuoso JDBC 4.0 driver
provides the <span class="computeroutput">virtuoso.java3.VirtuosoXid</span>,
<span class="computeroutput">virtuoso.java3.VirtuosoXADataSource</span>,
<span class="computeroutput">virtuoso.java3.VirtuosoXAConnection</span>, and
<span class="computeroutput">virtuoso.java3.VirtuosoXAResource</span> classes
which implement the interfaces
<span class="computeroutput">javax.transaction.xa.Xid</span>,
<span class="computeroutput">javax.transaction.xa.XADataSource</span>,
<span class="computeroutput">javax.sql.XAConnection</span>, and
<span class="computeroutput">javax.sql.XAResource</span> respectively.
The use if these interfaces is usually transparent for applications and the
application developer shouldn&#39;t bother with them. They are used only by
the JTS transaction manager which normally runs as a part of the J2EE
server.</p>
					<p>The task of the J2EE server
administrator is to setup the necessary Virtuoso XA datasources. The exact
procedure of this depends on the J2EE server in use (such as BEA WebLogic,
IBM WebSphere, etc). Generally, this includes two steps:</p>
					<ol>
      <li>
						<p>Include the JDBC driver&#39;s
jar file into J2EE server&#39;s class path.</p>
					    </li>
      <li>
						<p>Deploy an instance of
<span class="computeroutput">javax.transaction.xa.XADataSource</span> with
appropriately set properties into the J2EE server&#39;s JNDI repository.</p>
					    </li>
    </ol>
					<p>
The <span class="computeroutput">virtuoso.java3.VirtuosoXADataSource</span> class
is derived from <span class="computeroutput">virtuoso.java3.VirtuosoDataSource</span>
and inherits all of its properties. These properties has to be set as described
in the section <a href="VirtuosoDriverJDBC.html#jdbc4dsprops">Virtuoso Driver For JDBC 4.0 javax.sql.DataSource</a>.</p>
					<p>For example, the following has to
be done in case of Sun&#39;s J2EE Reference Implementation.</p>
					<ol>
      <li>
						<p>Add the path of
virtjdbc4.jar to the J2EE_CLASSPATH variable in the file
$(J2EE_HOME)/bin/userconfig.bat on Windows or $(J2EE_HOME)/bin/userconfig.sh on
Unix/Linux:</p>
<div>
          <pre class="programlisting">
    set J2EE_CLASSPATH=C:/Virtuoso/lib/virtjdbc4.jar
</pre>
        </div>
or
<div>
          <pre class="programlisting">
    J2EE_CLASSPATH=/home/login/virtuoso/lib/virtjdbc4.jar
    export J2EE_CLASSPATH
</pre>
        </div>
					    </li>
      <li>
						<p>Using the following
command add the XA datasource with JNDI name &quot;jdbc/Virtuoso&quot; which refers to
the Virtuoso server running on the same computer on port 1111:</p>
<div>
          <pre class="programlisting">
    j2eeadmin -addJdbcXADatasource jdbc/Virtuoso virtuoso.jdbc4.VirtuosoXADataSource -props serverName=localhost portNumber=1111
</pre>
        </div>
					    </li>
    </ol>
				<br />
				
					<a name="jdbcrs4" />
    <h4>7.4.4.4. JDBC 4.0 javax.sql.RowSet Driver Implementation</h4>
					<p>The Virtuoso JDBC 4.0 driver has two implementations of the
          <span class="computeroutput">javax.sql.RowSet</span> interface -
          <span class="computeroutput">virtuoso.javax.OPLCachedRowSet</span> and
          <span class="computeroutput">virtuoso.javax.OPLJdbcRowSet</span>.</p>
          <p>The <span class="computeroutput">virtuoso.javax.OPLCachedRowSet</span>
          class implements a totally disconnected, memory cached rowset and the
          <span class="computeroutput">virtuoso.javax.OPLJdbcRowset</span> class
          spans the rest of the JDBC API to implement it&#39;s methods.</p>
  <br />
  
      <a name="jdbcrdf4" />
    <h4>7.4.4.5. Extension datatype for RDF</h4>
      <p>The IRIs and RDF literals, kept in the Virtuoso RDF store are represented by a strings and structures. Thus accessing RDF objects needs special datatypes in order to distinguish strings from IRIs and to get language and datatype of the RDF literals.</p>
      <p>Therefore Virtuoso JDBC driver provides following classes for accessing RDF store: <span class="computeroutput">virtuoso.jdbc4.VirtuosoExtendedString</span> for IRIs and <span class="computeroutput">virtuoso.jdbc4.VirtuosoRdfBox</span> for RDF literal objects.</p>
      <p>
	  The class <span class="computeroutput">virtuoso.jdbc4.VirtuosoExtendedString</span> will be returned when a string representing an IRI is returned to the client. It has two members &quot;str&quot; and &quot;iriType&quot;, the &quot;str&quot; member keeps string representation of the IRI, &quot;iriType&quot; denote regular IRI or blank node with enum values VirtuosoExtendedString.IRI and VirtuosoExtendedString.BNODE.
      </p>
      <p>
	  If the RDF literal object have language or datatype specified then <span class="computeroutput">virtuoso.jdbc4.VirtuosoRdfBox</span> will be returned. The following methods could be used :
      </p>
      <div>
      <pre class="programlisting">
	  String toString () : returns string representation of the literal
	  String getType () : returns string containing the datatype  of the literal
	  String getLang () : returns language code for the literal
      </pre>
    </div>
      <p>
	  The following code snippet demonstrates how to use extension datatypes for RDF
      </p>
      <div>
      <pre class="programlisting">
    ... initialization etc. skipped for brevity
    boolean more = stmt.execute(&quot;sparql select * from &lt;gr&gt; where { ?x ?y ?z }&quot;);
    ResultSetMetaData data = stmt.getResultSet().getMetaData();
    while(more)
    {
	rs = stmt.getResultSet();
	while(rs.next())
	{
	    for(int i = 1;i &lt;= 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 &amp;&amp; (vs.strType &amp; 0x01) == 0x01)
			System.out.println (&quot;&lt;&quot; + vs.str +&quot;&gt;&quot;);
		    else if (vs.iriType == VirtuosoExtendedString.BNODE)
			System.out.println (&quot;&lt;&quot; + vs.str +&quot;&gt;&quot;);
		  }
		else if (o instanceof VirtuosoRdfBox) // Typed literal
		  {
		    VirtuosoRdfBox rb = (VirtuosoRdfBox) o;
		    System.out.println (rb.rb_box + &quot; lang=&quot; + rb.getLang() + &quot; type=&quot; + rb.getType());

		  }
		else if(stmt.getResultSet().wasNull())
		    System.out.println(&quot;NULL&quot;);
		else //
		{
		    System.out.println(s);
		}

	    }
	}
	more = stmt.getMoreResults();
    }
    ...
	    </pre>
    </div>
  <br />
                                <br />
				
					<a name="JDBCDriverInstallConfig" />
    <h3>7.4.5. Installation &amp; Configuration Steps</h3>
					<p>Perform the following steps in order to make use of your
    Virtuoso Drivers for JDBC:</p>
					<div class="note">
						<div class="notetitle">Note:</div>
						<p>You only have to perform these steps if a first attempt to use the
    Virtuoso Drivers for JDBC fails, the Virtuoso installer will attempt to configure these
    settings for you at installation time.</p>
					</div>
					<ol>
      <li>
							<p>Ensure your PATH environment variable is pointing to a
        version of the Java Virtual Machine (JVM) that is compatible with the version of the JDBC
        Driver Manager installed on your machine.  Consult the <a href="VirtuosoDriverJDBC.html#VirtuosoDriverPackaging">section 
        above</a> to double check.  You can also type the following command to verify Java
        versions:</p>

              <div>
          <pre class="programlisting">java -version</pre>
        </div>

						</li>
      <li>
							<p>Add the appropriate Virtuoso for JDBC &quot;jar&quot; file
        to your CLASSPATH environment variable.</p>
						</li>
      <li>
							<p>Attempt to make a connection using one of the
		sample JDBC Applications or Applets provided with your Virtuoso installation.</p>
						</li>
    </ol>

  <div class="note">
      <div class="notetitle">Note:</div>
  <p>If you have problems using the virtuoso JDBC driver despite your CLASSPATH being defined correctly, you
  may force the Java Virtual Machine to load a specific JDBC driver using: 
  <span class="computeroutput">-D</span> on the java command line: e.g:</p> 
  <p>
        <span class="computeroutput">-Djdbc.drivers=virtuoso.jdbc.Driver</span>.</p>
  <p>You can check the Virtuoso JDBC driver version from the command line using: 
  <span class="computeroutput">java virtuoso.jdbc.Driver</span>
      </p>
  </div>


				<br />
  <a name="JDBCDriverhibernate" />
    <h3>7.4.6. Virtuoso JDBC Driver Hibernate Support</h3>
    <a name="JDBCDriverhibernateintro" />
    <h4>7.4.6.1. Introduction</h4>
      <p>
      <strong>What</strong>
    </p>
      <p>Hibernate is a powerful, open source, high performance object/relational persistence and query service. Hibernate lets
you develop persistent classes following object-oriented idiom - including association, inheritance, polymorphism, composition, and
collections. Hibernate allows you to express queries in its own portable SQL extension (HQL), as well as in native SQL, or with an
object-oriented Criteria and Example API.
      </p>
      <p>
      <strong>Why</strong>
    </p>
      <p>Hibernate employs very aggressive, and very intelligent first and second level caching strategy, providing a high
performance and scalable development framework for Java. Greater cross portability and productivity can also be achieve using
hibernate as the same techniques can be employed across multiple databases.
      </p>
      <p>
      <strong>How</strong>
    </p>
      <p>Hibernate uses JDBC for accessing databases and may require a given database has a custom SQL dialect file that informs
Hibernate what SQL dialects are to be use for performing certain operations against the target database. Although not strictly
required, it should be used to ensure Hibernate Query Language (HQL) statements are correctly converted into the proper SQL
dialect for the underlying database. Virtuoso includes a new jar file called virt_dialect.jar containing the SQL dialect mappings
required between hibernate and Virtuoso and is used in conjunction to the Virtuoso JDBC Drivers (virtjdbc3.jar or virtjdbc4.jar).
      </p>
    <br />
    <a name="JDBCDriverhibernatesetupandtesting" />
    <h4>7.4.6.2. Setup and Testing</h4>
<p>Three <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VirtJdbcHibernate/Hibernate_Examples.zip">sample programs</a> are
provided to test Virtuoso hibernate support. Extract the contents of the zip file to a location of choice.
</p>
      <a name="JDBCDriverhibernatesetupandtestingreq" />
    <h5>7.4.6.2.1. Requirements</h5>
<ul>
  <li>
        <a href="https://www.hibernate.org/">Hibernate</a> 3.3 or higher</li>
  <li>JDK 5.0 or higher on any operating system</li>
  <li>Ant 1.6</li>
  <li>
        <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VirtJdbcHibernate/virt_dialect.jar">Virtuoso SQL Dialect jar file</a> (virt_dialect.jar)</li>
  <li>
        <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VirtJdbcHibernate/virtjdbc4.jar">Virtuoso JDBC Driver</a> (virtjdbc4.jar)</li>
</ul>
      <br />
      <a name="JDBCDriverhibernatesetupandtesting" />
    <h5>7.4.6.2.2. Building and running the example</h5>
        <p>The following Ant targets are available:</p>
<div>
      <pre class="programlisting">
clean         Clean the build directory
compile       Build example
run           Build and run example
</pre>
    </div>
      <br />
      <a name="JDBCDriverhibernateconstr" />
    <h5>7.4.6.2.3. Hibernate connection string</h5>
<p>Edit the file hibernate.cfg.xml in the &quot;bin&quot; and &quot;src&quot; directories of the hibernate application directory
with the correct connection attributes for the Virtuoso Server instance:</p>
<div>
      <pre class="programlisting">
$ more hibernate.cfg.xml
&lt;?xml version=&#39;1.0&#39; encoding=&#39;utf-8&#39;?&gt;
&lt;!DOCTYPE hibernate-configuration PUBLIC
        &quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;
        &quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;

&lt;hibernate-configuration&gt;

    &lt;session-factory&gt;

        &lt;!-- Database connection settings --&gt;
        &lt;property name=&quot;connection.driver_class&quot;&gt;virtuoso.jdbc4.Driver&lt;/property&gt;
        &lt;property name=&quot;connection.url&quot;&gt;jdbc:virtuoso://localhost:1111/&lt;/property&gt;
        &lt;property name=&quot;connection.username&quot;&gt;dba&lt;/property&gt;
        &lt;property name=&quot;connection.password&quot;&gt;dba&lt;/property&gt;

        &lt;!-- JDBC connection pool (use the built-in) --&gt;
        &lt;property name=&quot;connection.pool_size&quot;&gt;1&lt;/property&gt;

        &lt;!-- SQL dialect --&gt;
        &lt;property name=&quot;dialect&quot;&gt;virtuoso.hibernate.VirtuosoDialect&lt;/property&gt;

        &lt;!-- Enable Hibernate&#39;s current session context --&gt;
        &lt;property name=&quot;current_session_context_class&quot;&gt;thread&lt;/property&gt;

        &lt;!-- Disable the second-level cache  --&gt;
        &lt;property name=&quot;cache.provider_class&quot;&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;

        &lt;!-- Echo all executed SQL to stdout --&gt;
        &lt;property name=&quot;show_sql&quot;&gt;true&lt;/property&gt;

        &lt;!-- Drop and re-create the database schema on startup --&gt;
        &lt;property name=&quot;hbm2ddl.auto&quot;&gt;create&lt;/property&gt;

        &lt;mapping resource=&quot;events/Event.hbm.xml&quot;/&gt;

    &lt;/session-factory&gt;

&lt;/hibernate-configuration&gt;
</pre>
    </div>
<p>The key attributes being</p>
<ul>
  <li>
        <strong>connection.driver_class</strong> - Virtuoso JDBC Driver class name, typically virtuoso.jdbc4.Driver</li>
  <li>
        <strong>connection.url</strong> - Virtuoso JDBC Driver connect string for target Virtuoso server instance, of the
form jdbc:virtuoso://hostname:portno</li>
  <li>
        <strong>connection.username</strong> - Virtuoso Server username</li>
  <li>
        <strong>connection.password</strong> - Virtuoso Server password</li>
</ul>
      <br />
      <a name="JDBCDriverhibernatesetupandtestingexmp" />
    <h5>7.4.6.2.4. Examples</h5>
      <a name="JDBCDriverhibernatesetupandtestingexmp1" />
    <h6>Example 1</h6>
<p>This sample performs a simple insert and retrieval of data against the Virtuoso database.
</p>
<ol>
      <li>Open your command shell and change to the &quot;ex1&quot; directory</li>
      <li>The following required files need to be placed in the ./lib directory:
<div>
          <pre class="programlisting">
antlr-2.7.6.jar
commons-collections-3.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
hibernate3.jar
javassist-3.4.GA.jar
jta-1.1.jar
lib.lst
log4j-1.2.15.jar
slf4j-api-1.5.10.jar
slf4j-api-1.5.2.jar
slf4j-jcl-1.5.10.jar
virtjdbc4.jar
virt_dialect.jar
</pre>
        </div>
</li>
      <li>Run the example with &quot;ant run&quot; and read the log output on the console:
<div>
          <pre class="programlisting">
$ ant run
Buildfile: build.xml

clean:
   [delete] Deleting directory /Users/hughwilliams/hibernate/ex1/bin
    [mkdir] Created dir: /Users/hughwilliams/hibernate/ex1/bin

copy-resources:
     [copy] Copying 3 files to /Users/hughwilliams/hibernate/ex1/bin
     [copy] Copied 2 empty directories to 1 empty directory under /Users/hughwilliams/hibernate/ex1/bin

compile:
    [javac] Compiling 3 source files to /Users/hughwilliams/hibernate/ex1/bin

run:
     [java] Hibernate: insert into Event (EVENT_DATE, title) values (?, ?)
     [java] Hibernate: select identity_value()
     [java] Hibernate: insert into Event (EVENT_DATE, title) values (?, ?)
     [java] Hibernate: select identity_value()
     [java] Hibernate: select event0_.EVENT_ID as EVENT1_0_, event0_.EVENT_DATE as EVENT2_0_, event0_.title as title0_ from Event event0_
     [java] Event: My Event1 Time: 2010-03-14 03:27:51.0
     [java] Event: My Event2 Time: 2010-03-14 03:27:53.0

BUILD SUCCESSFUL
Total time: 3 seconds
</pre>
        </div>
</li>
      <li>Hibernate logging levels can be varied by changing the settings in the src/hibernate.cfg.xml and src/log4j.properties files.</li>
    </ol>
      <br />
      <a name="JDBCDriverhibernatesetupandtestingexmp2" />
    <h6>Example 2</h6>
<p>Hello World with Java Persistence</p>
<ol>
      <li>Open your command shell and change to the &quot;ex2&quot; directory</li>
      <li>The following required files need to be placed in the ./lib directory:
<div>
          <pre class="programlisting">

antlr-2.7.6.jar
asm-attrs.jar
asm.jar
c3p0-0.9.0.jar
cglib-2.1.3.jar
commons-collections-2.1.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
ejb3-persistence.jar
freemarker.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
hibernate-tools.jar
hibernate3.jar
javassist.jar
jboss-archive-browsing.jar
jta.jar
log4j-1.2.13.jar
virtjdbc4.jar
virt_dialect.jar
</pre>
        </div>
</li>
      <li>Use &quot;ant schemaexport&quot; to export a database schema automatically to the database. Ignore any errors about failing
ALTER TABLE statements, they are thrown because there are no tables when you run this for the first time.
<div>
          <pre class="programlisting">
$ ant schemaexport
Buildfile: build.xml

compile:

copymetafiles:

schemaexport:
[hibernatetool] Executing Hibernate Tool with a JPA Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool]
[hibernatetool]     drop table MESSAGES;
[hibernatetool]
[hibernatetool]     create table MESSAGES (
[hibernatetool]         MESSAGE_ID decimal(20,0)  identity,
[hibernatetool]         MESSAGE_TEXT varchar(255) null,
[hibernatetool]         NEXT_MESSAGE_ID decimal(20,0) null,
[hibernatetool]         primary key (MESSAGE_ID)
[hibernatetool]     );
[hibernatetool]
[hibernatetool]     alter table MESSAGES
[hibernatetool]         add
[hibernatetool]         foreign key (NEXT_MESSAGE_ID)
[hibernatetool]         references MESSAGES;

BUILD SUCCESSFUL
Total time: 2 seconds
</pre>
        </div>
</li>
      <li>Check the DDL that was also exported to the file helloworld-ddl.sql
<div>
          <pre class="programlisting">
$ more helloworld-ddl.sql

    drop table MESSAGES;

    create table MESSAGES (
        MESSAGE_ID decimal(20,0)  identity,
        MESSAGE_TEXT varchar(255) null,
        NEXT_MESSAGE_ID decimal(20,0) null,
        primary key (MESSAGE_ID)
    );

    alter table MESSAGES
        add
        foreign key (NEXT_MESSAGE_ID)
        references MESSAGES;
</pre>
        </div>
</li>
      <li>Run the example with &quot;ant run&quot; and read the log output on the console
<div>
          <pre class="programlisting">
$ ant run
Buildfile: build.xml

compile:

copymetafiles:

run:
     [java] 1 message(s) found:
     [java] Hello World with JPA

BUILD SUCCESSFUL
Total time: 2 seconds
</pre>
        </div>
</li>
      <li>Call ant run again
<div>
          <pre class="programlisting">
$ ant run
Buildfile: build.xml

compile:

copymetafiles:

run:
     [java] 2 message(s) found:
     [java] Hello World with JPA
     [java] Hello World with JPA

BUILD SUCCESSFUL
Total time: 2 seconds
</pre>
        </div>
</li>
      <li>If you call ant schemaexport again, all tables will be re-created </li>
      <li>Hibernate logging levels can be varied by changing the settings in the
src/etc/log4j.properties and src/etc/META-INF/persistence.xml files</li>
    </ol>
      <br />
      <a name="JDBCDriverhibernatesetupandtestingexmp3" />
    <h6>Example 3</h6>
<p>This sample performs more complex insert and retrieval of data against the Virtuoso database.</p>
<ol>
      <li>Open your command shell and change to the &quot;ex3&quot; directory</li>
      <li>The following required files need to be placed in the ./lib directory:
<div>
          <pre class="programlisting">
</pre>
        </div>
antlr-2.7.6.jar
commons-collections-3.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
hibernate3.jar
javassist-3.4.GA.jar
jta-1.1.jar
libs.lst
log4j-1.2.15.jar
slf4j-api-1.5.10.jar
slf4j-api-1.5.2.jar
slf4j-jcl-1.5.10.jar
virtjdbc4.jar
virt_dialect.jar
</li>
      <li>Run the example with &quot;ant run&quot; and read the log output on the console:
<div>
          <pre class="programlisting">
$ ant run
Buildfile: build.xml

clean:
   [delete] Deleting directory /Users/hughwilliams/hibernate/ex3/bin
    [mkdir] Created dir: /Users/hughwilliams/hibernate/ex3/bin

copy-resources:
     [copy] Copying 4 files to /Users/hughwilliams/hibernate/ex3/bin
     [copy] Copied 2 empty directories to 1 empty directory under /Users/hughwilliams/hibernate/ex3/bin

compile:
    [javac] Compiling 4 source files to /Users/hughwilliams/hibernate/ex3/bin
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.

run:
     [java] Hibernate: insert into EVENTS (EVENT_DATE, title) values (?, ?)
     [java] Hibernate: select identity_value()
     [java] Hibernate: insert into EVENTS (EVENT_DATE, title) values (?, ?)
     [java] Hibernate: select identity_value()
     [java] Hibernate: insert into PERSON (age, firstname, lastname) values (?, ?, ?)
     [java] Hibernate: select identity_value()
     [java] Hibernate: select person0_.PERSON_ID as PERSON1_2_0_, event2_.EVENT_ID as EVENT1_0_1_, person0_.age as age2_0_, person0_.firstname as firstname2_0_, person0_.lastname as lastname2_0_, event2_.EVENT_DATE as EVENT2_0_1_, event2_.title as title0_1_, events1_.PERSON_ID as PERSON2_0__, events1_.EVENT_ID as EVENT1_0__ from PERSON person0_ left outer join PERSON_EVENT events1_ on person0_.PERSON_ID=events1_.PERSON_ID left outer join EVENTS event2_ on events1_.EVENT_ID=event2_.EVENT_ID where person0_.PERSON_ID=?
     [java] Hibernate: select event0_.EVENT_ID as EVENT1_0_0_, event0_.EVENT_DATE as EVENT2_0_0_, event0_.title as title0_0_ from EVENTS event0_ where event0_.EVENT_ID=?
     [java] Hibernate: select participan0_.EVENT_ID as EVENT1_1_, participan0_.PERSON_ID as PERSON2_1_, person1_.PERSON_ID as PERSON1_2_0_, person1_.age as age2_0_, person1_.firstname as firstname2_0_, person1_.lastname as lastname2_0_ from PERSON_EVENT participan0_ left outer join PERSON person1_ on participan0_.PERSON_ID=person1_.PERSON_ID where participan0_.EVENT_ID=?
     [java] Hibernate: insert into PERSON_EVENT (PERSON_ID, EVENT_ID) values (?, ?)
     [java] Hibernate: update PERSON set age=?, firstname=?, lastname=? where PERSON_ID=?
     [java] Added person 1 to event 2
     [java] Hibernate: insert into PERSON (age, firstname, lastname) values (?, ?, ?)
     [java] Hibernate: select identity_value()
     [java] Hibernate: select person0_.PERSON_ID as PERSON1_2_0_, person0_.age as age2_0_, person0_.firstname as firstname2_0_, person0_.lastname as lastname2_0_ from PERSON person0_ where person0_.PERSON_ID=?
     [java] Hibernate: select emailaddre0_.PERSON_ID as PERSON1_0_, emailaddre0_.EMAIL_ADDR as EMAIL2_0_ from PERSON_EMAIL_ADDR emailaddre0_ where emailaddre0_.PERSON_ID=?
     [java] Hibernate: insert into PERSON_EMAIL_ADDR (PERSON_ID, EMAIL_ADDR) values (?, ?)
     [java] Hibernate: select person0_.PERSON_ID as PERSON1_2_0_, person0_.age as age2_0_, person0_.firstname as firstname2_0_, person0_.lastname as lastname2_0_ from PERSON person0_ where person0_.PERSON_ID=?
     [java] Hibernate: select emailaddre0_.PERSON_ID as PERSON1_0_, emailaddre0_.EMAIL_ADDR as EMAIL2_0_ from PERSON_EMAIL_ADDR emailaddre0_ where emailaddre0_.PERSON_ID=?
     [java] Hibernate: insert into PERSON_EMAIL_ADDR (PERSON_ID, EMAIL_ADDR) values (?, ?)
     [java] Added two email addresses (value typed objects) to person entity : 1
     [java] Hibernate: select event0_.EVENT_ID as EVENT1_0_, event0_.EVENT_DATE as EVENT2_0_, event0_.title as title0_ from EVENTS event0_
     [java] Event: My Event Time: 2010-03-14 03:30:02.0
     [java] Event: My Event Time: 2010-03-14 03:30:06.0

BUILD SUCCESSFUL
Total time: 5 seconds
</pre>
        </div>
</li>
      <li>Hibernate logging levels can be varied by changing the settings in the src/hibernate.cfg.xml and src/log4j.properties files.</li>
    </ol>
      <br />
      <a name="JDBCDriverhibernatesetupandtestingexmp4" />
    <h6>Example 4</h6>
      <p>This example demonstrates how to make Multi Thread Virtuoso connection using JDBC.</p>
      <p>It starts 3 threads: one thread executes SPARQL select and two threads execute SPARQL inserts:</p>
<div>
      <pre class="programlisting">
import java.util.*;
import java.sql.*;
import java.math.*;

public class MTtest extends Thread {

  int mode = 0;
  int startId = 0;

  static  String urlDB = &quot;jdbc:virtuoso://localhost:1111&quot;;

 
 public MTtest(int _mode, int _init) {
   mode = _mode;
   startId = _init;
 }



 void prnRs(ResultSet rs)
 {
   try {
     ResultSetMetaData rsmd;

     System.out.println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;);
     rsmd = rs.getMetaData();
     int cnt = rsmd.getColumnCount();

       while(rs.next()) {
         Object o;

         System.out.print(&quot;Thread:&quot;+Thread.currentThread().getId()+&quot;  &quot;);
         for (int i = 1; i &lt;= cnt; i++) {
           o = rs.getObject(i);
           if (rs.wasNull())
             System.out.print(&quot;&lt;NULL&gt; &quot;);
           else
             System.out.print(&quot;[&quot;+ o + &quot;] &quot;);
         }
         System.out.println();
       }

   } catch (Exception e) {
     System.out.println(e);
     e.printStackTrace();
   }
   System.out.println(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;);
 }




 public static void main(String argv[])
 {
  try {

    Class.forName(&quot;virtuoso.jdbc3.Driver&quot;);

    Connection conn = DriverManager.getConnection(urlDB,&quot;dba&quot;,&quot;dba&quot;);
    Statement st = conn.createStatement();

    st.execute(&quot;sparql clear graph &lt;mttest&gt;&quot;);
    st.execute(&quot;sparql insert into graph &lt;mttest&gt; { &lt;xxx&gt; &lt;P01&gt; \&quot;test1\&quot; }&quot;);
    st.execute(&quot;sparql insert into graph &lt;mttest&gt; { &lt;xxx&gt; &lt;P01&gt; \&quot;test2\&quot; }&quot;);
    st.execute(&quot;sparql insert into graph &lt;mttest&gt; { &lt;xxx&gt; &lt;P01&gt; \&quot;test3\&quot; }&quot;);
    st.execute(&quot;sparql insert into graph &lt;mttest&gt; { &lt;xxx&gt; &lt;P01&gt; \&quot;test4\&quot; }&quot;);
    st.execute(&quot;sparql insert into graph &lt;mttest&gt; { &lt;xxx&gt; &lt;P01&gt; \&quot;test5\&quot; }&quot;);
    conn.close();


    int init = 0;

    for(int i=0; i &lt; 2; i++) {
      MTtest thr1 = new MTtest(1, init);
      init+=10;

      MTtest thr2 = new MTtest(0, init);
      init+=10;

      MTtest thr3 = new MTtest(0, init);
      init+=10;

      thr1.start();
      thr2.start();
      thr3.start();

      thr1.join();
      thr2.join();
      thr3.join();
    }

    System.out.println(&quot;===End===&quot;);

  } catch (Exception e) {
    System.out.print(e);
    e.printStackTrace();
  }
 }


 public void run( ) 
 {
  try {

    Connection conn = DriverManager.getConnection(urlDB,&quot;dba&quot;,&quot;dba&quot;);
    Statement st;

    st = conn.createStatement();

    if (mode == 1) 
    {
      String query = &quot;sparql SELECT * from &lt;mttest&gt; WHERE {?s ?p ?o}&quot;;
      ResultSet rs = st.executeQuery(query);
      prnRs(rs);
    }
    else
    {
      long id = Thread.currentThread().getId();
      for (int i =0; i &lt; 5; i++)
        st.execute(&quot;sparql insert into graph &lt;mttest&gt; { &lt;xxx&quot;+startId+&quot;&gt; &lt;P&quot;+id+&quot;&gt; \&quot;test&quot;+i+&quot;\&quot; }&quot;);

      System.out.println(&quot;\nThread:&quot;+Thread.currentThread().getId()+&quot;  ===Rows Inserted===&quot;);
    }


    conn.close();
  
  } catch (SQLException e) {
        System.out.println(&quot;===========================================================&quot;);
        System.out.println(&quot;&gt;&gt;[&quot;+e.getMessage()+&quot;]&quot;);
        System.out.println(&quot;&gt;&gt;[&quot;+e.getErrorCode()+&quot;]&quot;);
        System.out.println(&quot;&gt;&gt;[&quot;+e.getSQLState()+&quot;]&quot;);
        System.out.println(e);
        System.out.println(&quot;===========================================================&quot;);
        e.printStackTrace();
        System.exit(-1);
  } catch (Exception e) {
        System.out.println(&quot;===========================================================&quot;);
        System.out.println(e);
        System.out.println(&quot;===========================================================&quot;);
        e.printStackTrace();
        System.exit(-1);
  }
 } // run( )





}	
</pre>
    </div>      
      <br />      
      <br />
    <br />
  <br />
			<table border="0" width="90%" id="navbarbottom">
    <tr>
        <td align="left" width="33%">
          <a href="odbcimplementation.html" title="Virtuoso Driver for ODBC">Previous</a>
          <br />Virtuoso Driver for ODBC</td>
     <td align="center" width="34%">
          <a href="accessinterfaces.html">Chapter Contents</a>
     </td>
        <td align="right" width="33%">
          <a href="virtoledb.html" title="OLE DB Provider for Virtuoso">Next</a>
          <br />OLE DB Provider for Virtuoso</td>
    </tr>
    </table>
  </div>
  <div id="footer">
    <div>Copyright© 1999 - 2009 OpenLink Software All rights reserved.</div>
   <div id="validation">
    <a href="http://validator.w3.org/check/referer">
        <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" />
    </a>
    <a href="http://jigsaw.w3.org/css-validator/">
        <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
    </a>
   </div>
  </div>
 </body>
</html>