<rdf:RDF
    xmlns:s='http://snipsnap.org/rdf/snip-schema#'
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    xml:base='http://www.stefanrufer.ch/snipsnap/rdf'>
    <s:Snip rdf:about='http://www.stefanrufer.ch/snipsnap/rdf#Virtual+Brain/Java/snipsnap+contributions'
         s:cUser='stefan'
         s:oUser='stefan'
         s:mUser='stefan'>
        <s:name>Virtual Brain/Java/snipsnap contributions</s:name>
        <s:content>1 DB-View Macro&#xD;&#xA;&#xD;&#xA;1.1 Description &#xD;&#xA;Queries a database and renders tabular result. Example: \{dbview:java:comp/env/jdbc/testDS|select * from salary\}. &#xD;&#xA;&#xD;&#xA;1.1 Parameters&#xD;&#xA;1. fully qualified JNDI datasource name to be used for database access (mandatory)&#xD;&#xA;1. SQL string that will produce the tabular data to be rendered (mandatory)&#xD;&#xA;1. header off - set to &apos;true&apos; if rendering of the resulting table must not include a header row (optional)&#xD;&#xA;&#xD;&#xA;1.1 Example result&#xD;&#xA;{table}&#xD;&#xA;ID | EMP_ID | SALARY | STAMP&#xD;&#xA;100 | 19382 | 10000 | foo-20050530&#xD;&#xA;101 | 29809 | 12345 | foo-2003-0404&#xD;&#xA;{table}&#xD;&#xA;&#xD;&#xA;1.1 Download&#xD;&#xA;See attachements of this snip.&#xD;&#xA;&#xD;&#xA;1.1 Installing&#xD;&#xA;&#xD;&#xA;Copy dbview-macro.jar to your snipsnap/WEB-INF/lib directory. Then set up the data source:&#xD;&#xA;&#xD;&#xA;1.1.1 Define the datasource &#xD;&#xA;For Tomcat, this is done in the tomcat/conf/server.xml file in the snipsnap context:&#xD;&#xA;{code:xml}&#xD;&#xA;&lt;Context path=&quot;/snipsnap&quot; docBase=&quot;/tomcat-5.0/webapps/snipsnap&quot; debug=&quot;5&quot; reloadable=&quot;true&quot;&gt;&#xD;&#xA;  &lt;Resource name=&quot;jdbc/testDS&quot; auth=&quot;Container&quot; type=&quot;javax.sql.DataSource&quot;/&gt;&#xD;&#xA;  &lt;ResourceParams name=&quot;jdbc/testDS&quot;&gt;&#xD;&#xA;    &lt;parameter&gt;&#xD;&#xA;      &lt;name&gt;factory&lt;/name&gt;&#xD;&#xA;      &lt;value&gt;org.apache.commons.dbcp.BasicDataSourceFactory&lt;/value&gt;&#xD;&#xA;    &lt;/parameter&gt;&#xD;&#xA;    &lt;!-- MySQL dB username and password for dB connections  --&gt;&#xD;&#xA;    &lt;parameter&gt;&#xD;&#xA;     &lt;name&gt;username&lt;/name&gt;&#xD;&#xA;     &lt;value&gt;foo&lt;/value&gt;&#xD;&#xA;    &lt;/parameter&gt;&#xD;&#xA;    &lt;parameter&gt;&#xD;&#xA;     &lt;name&gt;password&lt;/name&gt;&#xD;&#xA;     &lt;value&gt;bar&lt;/value&gt;&#xD;&#xA;    &lt;/parameter&gt;    &#xD;&#xA;    &lt;parameter&gt;&#xD;&#xA;       &lt;name&gt;driverClassName&lt;/name&gt;&#xD;&#xA;       &lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt;&#xD;&#xA;    &lt;/parameter&gt;&#xD;&#xA;    &lt;parameter&gt;&#xD;&#xA;      &lt;name&gt;url&lt;/name&gt;&#xD;&#xA;      &lt;value&gt;jdbc:mysql://localhost/test?autoReconnect=true&lt;/value&gt;&#xD;&#xA;    &lt;/parameter&gt;&#xD;&#xA;  &lt;/ResourceParams&gt;&#xD;&#xA;&lt;/Context&gt;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;1.1.1 Reference the datasource&#xD;&#xA;For Tomcat, this is added in the snipsnap/WEB-INF/web.xml file:&#xD;&#xA;{code:xml}&#xD;&#xA;&lt;resource-ref&gt;&#xD;&#xA;  &lt;res-ref-name&gt;&#xD;&#xA;    jdbc/testDS&#xD;&#xA;  &lt;/res-ref-name&gt;&#xD;&#xA;  &lt;res-type&gt;&#xD;&#xA;    javax.sql.DataSource&#xD;&#xA;  &lt;/res-type&gt;&#xD;&#xA;  &lt;res-auth&gt;&#xD;&#xA;    Container&#xD;&#xA;  &lt;/res-auth&gt;&#xD;&#xA;&lt;/resource-ref&gt;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;1.1.1 Use the datasource&#xD;&#xA;In the dbview-macro, a datasource as defined above would be referenced as follows:&#xD;&#xA;&#xD;&#xA;{code:none}&#xD;&#xA;\{dbview:java:comp/env/jdbc/testDS|select * from foobar\}. &#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;1.1 WARNING&#xD;&#xA; - Datasource name and SQL query can be seen by EVERYONE, even if NOT LOGGED IN. &#xD;&#xA; - If logged in, users may use arbitrary SQL queries and therefore gain access to any data provided by the data source available. &#xD;&#xA;Please consider this before installing the macro on any site.&#xD;&#xA;</s:content>
        <s:mTime>2005-06-05 21:16:23.818</s:mTime>
        <s:cTime>2005-06-05 21:16:00.404</s:cTime>
        <s:comments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:snipLinks>
            <rdf:Bag>
                <rdf:li rdf:resource='#snipsnap-index'/>
                <rdf:li rdf:resource='http://www.stefanrufer.ch/snipsnap/rdf#Virtual Brain/Java'/>
                <rdf:li rdf:resource='http://www.stefanrufer.ch/snipsnap/rdf#Virtual Brain'/>
                <rdf:li rdf:resource='http://www.stefanrufer.ch/snipsnap/rdf#stefan/SnipSnap Things'/>
                <rdf:li rdf:resource='http://www.stefanrufer.ch/snipsnap/rdf#stefan/Snipsnap Things'/>
            </rdf:Bag>
        </s:snipLinks>
        <s:attachments>
            <rdf:Bag>
                <rdf:li>
                    <s:Attachment rdf:about='http://www.stefanrufer.ch/snipsnap/space/Virtual+Brain/Java/snipsnap+contributions/dbview-macro-src.jar'
                         s:fileName='dbview-macro-src.jar'
                         s:contentType='application/zip'
                         s:size='6632'>
                        <s:date>Sun Jun 05 21:16:23 CEST 2005</s:date>
                    </s:Attachment>
                </rdf:li>
                <rdf:li>
                    <s:Attachment rdf:about='http://www.stefanrufer.ch/snipsnap/space/Virtual+Brain/Java/snipsnap+contributions/dbview-macro.jar'
                         s:fileName='dbview-macro.jar'
                         s:contentType='application/x-java'
                         s:size='6483'>
                        <s:date>Sun Jun 05 21:16:15 CEST 2005</s:date>
                    </s:Attachment>
                </rdf:li>
            </rdf:Bag>
        </s:attachments>
    </s:Snip>
</rdf:RDF>

