You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Seema Richard <Se...@ust-global.com> on 2009/12/02 05:01:21 UTC

Problem when using CLOB for storing template in Oracle DB

Hi,

 

We are using DataSourceResourceLoader for getting the velocity template
from an Oracle table. This works fine when the template field is
varchar. But when the field type was changed to CLOB, the content is
empty. Is there any solution to this problem?

 

Here is the example code.

 

<code>

import java.io.StringWriter;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.Statement;

 

import javax.sql.DataSource;

 

import org.apache.log4j.BasicConfigurator;

import org.apache.log4j.Logger;

import org.apache.velocity.Template;

import org.apache.velocity.VelocityContext;

import org.apache.velocity.app.VelocityEngine;

import org.apache.velocity.runtime.RuntimeConstants;

import
org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader;

import org.springframework.context.ApplicationContext;

import
org.springframework.context.support.ClassPathXmlApplicationContext;

public class Example2

{

       public static String LOGGER_NAME = "velexample";

 

    public static void main( String[] args )

        throws Exception

    {

      ApplicationContext appContext = new
ClassPathXmlApplicationContext("dataAccessContext-framework.xml");

      DataSource dataSource =
(DataSource)appContext.getBean("dataSource");

      BasicConfigurator.configure();

 

        Logger log = Logger.getLogger( LOGGER_NAME );

 

        log.info("Log4jLoggerExample: ready to start velocity");

 

        /*

         *  now create a new VelocityEngine instance, and

         *  configure it to use the category

         */

 

 

        VelocityEngine ve = new VelocityEngine();

        

        /*  Setting the properties of the velocity engine */

        DataSourceResourceLoader ds = new DataSourceResourceLoader();

        ds.setDataSource(dataSource);

        ve.setProperty("resource.loader","ds");

        ve.setProperty("ds.resource.loader.instance",ds);

 
ve.setProperty("ds.resource.loader.resource.table","TB_VELOCITY_TEMPLATE
");

 
ve.setProperty("ds.resource.loader.resource.keycolumn","TEMPLATE_ID");

       //
ve.setProperty("ds.resource.loader.resource.templatecolumn","TEMP_DEF");

 
//ve.setProperty("ds.resource.loader.resource.templatecolumn","TEMPLATE_
LONG_DEFINITION");

 
ve.setProperty("ds.resource.loader.resource.templatecolumn","TEMPLATE_DE
FINITION");

 
ve.setProperty("ds.resource.loader.resource.timestampcolumn","TIME_STAMP
");

        ve.setProperty("ds.resource.loader.cache","false");

 
ve.setProperty("ds.resource.loader.modificationCheckInterval",60L);

 

        ve.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,

        "org.apache.velocity.runtime.log.Log4JLogChute" );

 

        ve.setProperty("runtime.log.logsystem.log4j.logger",

                      LOGGER_NAME);

 

        /*  Initializing the velocity engine  */

        ve.init();

                   

        /*  next, get the Template  */

        Template t = ve.getTemplate("1");

        //Template t = ve.getTemplate("template602");

        System.out.println("111"+t.getData());

        /*  create a context and add data */

        VelocityContext context = new VelocityContext();

        context.put("user", "World");

        /* now render the template into a StringWriter */

        StringWriter writer = new StringWriter();

        t.merge( context, writer );

        /* show the World */

        System.out.println("222");

        System.out.println( writer.toString() ); 

        System.out.println("333");

    }

}

 

</code>

 

Thanks,

Seema