The easy Weblog and Wiki Software
[ start | index | login ]
start > stefanrufer > dbview

dbview

Created by stefanrufer. Last edited by stefanrufer, 3 years and 44 days ago. Viewed 504 times. #8
[diff] [history] [edit] [rdf]
labels
attachments
dbview-macro-src.jar (6618)
dbview-macro.jar (6483)

Description

Queries a database and renders tabular result. Example: {dbview:java:comp/env/jdbc/testDS|select * from salary}.

Parameters

  1. fully qualified JNDI datasource name to be used for database access (mandatory)
  2. SQL string that will produce the tabular data to be rendered (mandatory)
  3. header off - set to 'true' if rendering of the resulting table must not include a header row (optional)

Example result

IDEMP_IDSALARYSTAMP
1001938210000foo-20050530
1012980912345foo-2003-0404

Download

See attachements of this snip.

Installing

Copy dbview-macro.jar to your snipsnap/WEB-INF/lib directory. Then set up the data source:

Define the datasource

For Tomcat, this is done in the tomcat/conf/server.xml file in the snipsnap context:
<Context path="/snipsnap" docBase="/tomcat-5.0/webapps/snipsnap" debug="5" reloadable="true">
  <Resource name="jdbc/testDS" auth="Container" type="javax.sql.DataSource"/>
  <ResourceParams name="jdbc/testDS">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <!-- MySQL dB username and password for dB connections  -->
    <parameter>
     <name>username</name>
     <value>foo</value>
    </parameter>
    <parameter>
     <name>password</name>
     <value>bar</value>
    </parameter>    
    <parameter>
       <name>driverClassName</name>
       <value>com.mysql.jdbc.Driver</value>
    </parameter>
    <parameter>
      <name>url</name>
      <value>jdbc:mysql://localhost/test?autoReconnect=true</value>
    </parameter>
  </ResourceParams>
</Context>

Reference the datasource

For Tomcat, this is added in the snipsnap/WEB-INF/web.xml file:
<resource-ref>
  <res-ref-name>
    jdbc/testDS
  </res-ref-name>
  <res-type>
    javax.sql.DataSource
  </res-type>
  <res-auth>
    Container
  </res-auth>
</resource-ref>

Use the datasource

In the dbview-macro, a datasource as defined above would be referenced as follows:

{dbview:java:comp/env/jdbc/testDS|select * from foobar}.

WARNING

  • Datasource name and SQL query can be seen by EVERYONE, even if NOT LOGGED IN.
  • If logged in, users may use arbitrary SQL queries and therefore gain access to any data provided by the data source available.
Please consider this before installing the macro on any site.

no comments | post comment

What is SnipSnap?
SnipSnap is a free and easy to install weblog and wiki tool written in Java.

SnipSnap download
Current version: 1.0b3-uttoxeter
Try our >>Web Start Demo!

Resources

5567 Users and 13712 Snips. Installed 6 years and 8 days ago

Logged in Users: (2)
… and 10 Guests.

snipsnap-changed for older changes.

< July 2008 >
SunMonTueWedThuFriSat
12345
6789101112
13141516171819
20212223242526
2728293031

snipsnap
Listed on BlogShares
XHTML 1.0 validated
CSS validated
RSS 2.0 validated
RSS Feed

pico-powered

Powered by SnipSnap 1.0b3-uttoxeter
YourKit >>Java Profiler

Fraunhofer FIRST

snipsnap.org | Copyright 2000-2006 Fraunhofer FIRST