Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: execute insert from JS step

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    133

    Default execute insert from JS step

    Hi all.
    I want to execute INSERT from JS step, but with a fireToDB i have this error:
    "the executeQuery method must return a result set".

    I red that fireToDB should only be used for SELECT statements, but actually works in DB, beacuse the insert was successful executed, but in spoon it's error.

    Is there another way to execute insert??

    Thanks

    Vale

  2. #2
    Join Date
    Sep 2010
    Posts
    133

    Default

    I did it.

    This is the trasformation

    ex_insert.ktr

  3. #3
    Join Date
    Dec 2014
    Posts
    3

    Default

    This solutions is goot, perhaps the question is old but i what to add some information because your reply has been useful for me today.
    With that solution the db stay open, only is needed to add db.disconnect(); after the execution of the statement.
    This is the final result:
    var Database = Packages.org.pentaho.di.core.database.Database;
    var DatabaseMeta = Packages.org.pentaho.di.core.database.DatabaseMeta;

    var transMeta = _step_.getTransMeta();
    var dbInfo = transMeta.findDatabase("your connection");

    db = new Database(transMeta,dbInfo); //Database(dbInfo) in 3.2 version
    db.connect();
    db.execStatement("insert into [Sheet1$A1:C10000] values ('esdde','eesdddes','asddddfasd')");

    db.disconnect();

    Thanks Todvals

    db.disconnect();
    db.disconnect();
    db.disconnect();

  4. #4
    Join Date
    Jul 2007
    Posts
    247

    Default

    I always wonder why people try to reinvent the wheel... why don't you use proper steps that were designed for these tasks (SQL step, Insert/Update step, Table Output step). Stay away from using SQL functions in the JS step, it will cause more trouble than you think...

    Regards,
    Ben

  5. #5
    Join Date
    Sep 2010
    Posts
    133

    Default

    I need it from JS and not from SQL step because I have to repeat it many times...so in a trasformation I need to insert maybe 15 SQL step...so I chose to implement a function that execute SQL statementent and I call it from JS all times I need...
    It's not for reinvent the wheel, but I'm try to optimize my ETL

    Vale

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.