Results 1 to 2 of 2
  1. #1
    mjwoodford is offline Member
    Join Date
    Sep 2009
    Posts
    6
    Rep Power
    0

    Default Unexpected characters using PrintWriter

    Hi, I am using Velocity to generate a script file, the script file producted however contains an extraneous last line as follows:

    'java.io.PrintWriter@5f805f80'

    The code is:

    private void createDSJython(){
    try{
    //build Jython
    VelocityEngine ve = new VelocityEngine();
    ve.init();
    VelocityContext context = new VelocityContext();
    context.put("jndiName", dsAttrs);
    Template t = ve.getTemplate( "testDs.vm" );
    /* now render the template into a Writer */

    BufferedWriter output = null;
    File file = new File("D://createDs.py");
    FileWriter fl = new FileWriter(file);
    output = new BufferedWriter(fl);
    PrintWriter print = new PrintWriter(output);
    t.merge(context, print);
    print.write(print.toString());

    if (print != null) {
    print.flush();
    print.close();
    }
    }catch(Exception e){
    e.printStackTrace();
    }
    }

    and the Velocity templat, 'testDs.vm' is:

    #foreach( $jndiName in $jndiName )
    AdminTask.createDatasource(newjdbc, '[-name "ValidSystems DataSource" -jndiName $jndiName.getJndiName() -dataStoreHelperClassName com.ibm.websphere.rsadapter.DB2UniversalDataStoreH elper -componentManagedAuthenticationAlias ' + uname + ' -xaRecoveryAuthAlias ' + uname + ' -configureResourceProperties [[databaseName java.lang.String CJSE] [driverType java.lang.Integer 4] [serverName java.lang.String ' + serverName + '] [portNumber java.lang.Integer ' + portNumber + ']]]')
    #end

    Any help, much appreciated!

    Thanks,

    Matt

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    What is this supposse to do?

    Java Code:
    t.merge(context, print);
    print.write(print.toString());
    In any case, the last line is where the line in your post is coming from. For details read the "toString()" method description in Object.

Similar Threads

  1. Error: unexpected type
    By silvia in forum New To Java
    Replies: 3
    Last Post: 02-05-2010, 09:54 PM
  2. difference printwriter & out.println
    By tushar88 in forum Java Servlet
    Replies: 1
    Last Post: 03-10-2009, 05:15 AM
  3. unexpected type
    By one in forum New To Java
    Replies: 13
    Last Post: 01-20-2009, 09:32 AM
  4. Using Printwriter (java.io.*)
    By LifeWithJava in forum New To Java
    Replies: 3
    Last Post: 12-25-2008, 08:07 AM
  5. Unexpected Error
    By Mir in forum New To Java
    Replies: 10
    Last Post: 07-07-2008, 07:57 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
  •