Results 1 to 7 of 7
  1. #1
    jss
    jss is offline Member
    Join Date
    Sep 2014
    Posts
    3
    Rep Power
    0

    Default Looking for documentation/example of how to use velocity to create mysql tables

    Need to locate ways to create mysql table dynamically using velocity engine and am looking for working example that I can follow and read from.

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: Looking for documentation/example of how to use velocity to create mysql tables

    Break it down into smaller chunks:
    - Make a SQL template
    - Get the variables in there
    - Get Velocity to parse it
    - Use the returned String to fire at your database
    Last edited by SurfMan; 09-05-2014 at 10:15 PM.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    jss
    jss is offline Member
    Join Date
    Sep 2014
    Posts
    3
    Rep Power
    0

    Default Re: Looking for documentation/example of how to use velocity to create mysql tables

    Quote Originally Posted by SurfMan View Post
    Break it down into smaller chunks:
    - Make a SQL template
    - Get the variables in there
    - Get Velocity to parse it
    - Use the returned String to fire at your database


    @SurfMan: Looking for an example or tutorila to do that. I have the sql table creating script. its the variables and the rest I need to figure out

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: Looking for documentation/example of how to use velocity to create mysql tables

    Have you used Velocity before?
    If so, then I'm not sure where exactly you're stuck.
    Perhaps if you put forward some code showing what you've achieved then we can start to pick it apart.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Looking for documentation/example of how to use velocity to create mysql tables

    I hope it is clear that Velocity is only a templating engine, it is not a full web framework which can actually be used to perform business logic - such as doing database interactions. At best you can use Velocity to generate an SQL script from a template. The user guide should be enough to get that done:

    Apache Velocity - Velocity User Guide

    I am going to read minds here and anticipate the remark "But that shows only HTML" - no, it shows templating of text data. HTML is text data, SQL is text data. The usage of Velocity is the same.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    jss
    jss is offline Member
    Join Date
    Sep 2014
    Posts
    3
    Rep Power
    0

    Default Re: Looking for documentation/example of how to use velocity to create mysql tables

    Quote Originally Posted by Tolls View Post
    Have you used Velocity before?
    If so, then I'm not sure where exactly you're stuck.
    Perhaps if you put forward some code showing what you've achieved then we can start to pick it apart.
    Have never used velocity before.

    This is my code in java [spring mvc]

    String renderedTemplate = "";

    Map<String, Object> velocityModel = new HashMap<String, Object>();

    velocityModel.put("UserName", userName);
    velocityModel.put("UserProperties", userProperties);

    renderedTemplate = getVelocityTemplateService().mergeTemplate("UserTa ble.vm", null);

    runSqlScripString(renderedTemplate);


    The .vm file is a

    DROP TABLE IF EXISTS `UserTable_${UserName}`;
    $$
    CREATE TABLE `UserTable_${UserName}`
    (`id` bigint(20) NOT NULL AUTO_INCREMENT,
    `guid` CHAR(36) ASCII,
    `user_name` varchar(128) NOT NULL,
    #foreach( $prop in $propList )
    `$prop.prop_name` #parse("columnDataTypeConvertion.vm") DEFAULT NULL,
    #end
    PRIMARY KEY (`id`)
    )ENGINE=InnoDB DEFAULT CHARSET=utf8;
    $$


    I am getting this exception
    Lexical error: org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: Looking for documentation/example of how to use velocity to create mysql tables

    You're not passing in any values.
    You need to create a Context containing the values you want to send into the template. This is not a HashMap, but functions in the same way (key and value pairs).
    Not sure what that getVelocityTemplateService is giving you or is expecting, but I'm going to guess that that 'null' should be a Context? Or possibly your Map, but that's your code so I can't say.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. inserting into multiple tables mysql using java
    By bankTechy in forum New To Java
    Replies: 5
    Last Post: 09-26-2013, 04:52 PM
  2. Issues populating MySQL tables
    By Randy_Dennis in forum JDBC
    Replies: 2
    Last Post: 01-12-2011, 08:49 AM
  3. XSD Schema to MySql Tables
    By shellrandhawa in forum XML
    Replies: 0
    Last Post: 09-27-2010, 02:49 AM
  4. [SOLVED] How to create documentation easily?
    By Ypsilon IV in forum New To Java
    Replies: 1
    Last Post: 04-25-2009, 07:41 PM
  5. How to use one form to submit data to 2 tables on mysql
    By kwesiaryee in forum New To Java
    Replies: 2
    Last Post: 10-10-2008, 01:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •