ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject RE: SQLExec Class usage
Date Mon, 15 Mar 2004 13:11:56 GMT
You have to set the project for the sql-task.
    
  private void startAntSQLTask(){

    SQLExec sqlExec = new SQLExec();
    sqlExec.setSrc(new File(sqlFile));

    Project p = new Project();
    p.init();
    p.addBuildListener(createLogger());
    //p.setCoreLoader(getClass().getClassLoader());

    // HERE
    sqlExec.setProject(p);
    ...
  }


Tasks can log messages. But the base implementation inside Task (baseclass)
is 
    public void log(String msg, int msgLevel) {
        getProject().log(this, msg, msgLevel);
    }
And if getProject() returns null you´ll get the NPE. ... maybe we should
catch that ...


Jan


> -----Original Message-----
> From: Ashish Bharti [mailto:AshishB@ocwen.co.in]
> Sent: Monday, March 15, 2004 1:44 PM
> To: 'user@ant.apache.org'
> Subject: RE: SQLExec Class usage
> 
> 
> Also The Exception Stack is::
> 
> java.lang.NullPointerException
> 	at org.apache.tools.ant.Task.log(Task.java:324)
> 	at
> org.apache.tools.ant.taskdefs.JDBCTask.getConnection(JDBCTask.
> java:338)
> 	at 
> org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:358)
> 	at
> com.otx.framework.scheduler.tasks.SQLTaskWrapper.startAntSQLTa
> sk(SQLTaskWrap
> per.java:180)
> 	at
> com.otx.framework.scheduler.tasks.SQLTaskWrapper.<init>(SQLTas
> kWrapper.java:
> 210)
> 	at
> com.otx.framework.scheduler.tasks.SQLTaskWrapper.main(SQLTaskW
> rapper.java:19
> 7)
> Exception in thread "main" 
> 
> 
> Regards,
> Ashish
> 
> 
> > -----Original Message-----
> > From:	Ashish Bharti 
> > Sent:	Monday, March 15, 2004 6:13 PM
> > To:	'user@ant.apache.org'
> > Subject:	SQLExec Class usage
> > 
> > Hello,
> > 
> > I am trying to run any .sql script provided, through Java, 
> for which i am
> > using the SQLExec class.I am passing all parameters through 
> Java and dont
> > want to use any config.build file
> > 
> > Cant get any information regarding the same on the 
> mail-list.Guess I am
> > not able to set the classpath correctly.
> > 
> > Would Appreciate any help ! Please CC any suggestions to my ID.
> > 
> > The program is attached below...[I have deleted the 
> irrelavent portion...
> > so might not compile...]
> > 
> > 
> > /**
> >  * Title:
> >  * Description:
> >  * Copyright:    Copyright (c) 2003
> >  * Company:
> >  * @author
> >  * @version 1.0
> >  */
> > import java.util.*;
> > import java.io.*;
> > import org.apache.log4j.Logger;
> > // Ant SQL Task API
> > import org.apache.tools.ant.taskdefs.SQLExec;
> > import org.apache.tools.ant.types.*;
> > import org.apache.tools.ant.Project;
> > import org.apache.tools.ant.Location;
> > import org.apache.tools.ant.BuildLogger;
> > import org.apache.tools.ant.DefaultLogger;
> > 
> > 
> > 
> > public class SQLTaskWrapper {
> > 
> >   public static final String YES ="Y";
> >   private TaskCommunicator taskCommunicator = null;
> >   private ArrayList parameterModelList = null;
> >   private ArrayList streamModelList = null;
> >   private boolean runFL = true;
> >   private boolean isPaused = false;
> >   private String sqlFile = null;
> >   private String outputFile = null;
> >   private String delimiter = null;
> >   private String autoCommit = null;
> >   private String driver = null;
> >   private String url = null;
> >   private String userName = null;
> >   private String password = null;
> > 
> > 
> >   private static BuildLogger createLogger() {
> >       BuildLogger logger = null;
> >       logger = new DefaultLogger();
> >       logger.setMessageOutputLevel(Project.MSG_INFO);
> >       logger.setOutputPrintStream(System.out);
> >       logger.setErrorPrintStream(System.err);
> >       logger.setEmacsMode(false);
> > 
> >       return logger;
> >   }
> > 
> >   private void startAntSQLTask(){
> > 
> >     SQLExec sqlExec = new SQLExec();
> >     sqlExec.setSrc(new File(sqlFile));
> > 
> >     Project p = new Project();
> >     p.init();
> >     p.addBuildListener(createLogger());
> >     //p.setCoreLoader(getClass().getClassLoader());
> > 
> >     Path path = new Path(p);
> > 
> >     Path.PathElement pathElement1 = path.createPathElement();
> >     pathElement1.setPath(
> >  
> > 
> "C:\\Projects\\JavaFramework\\Source\\Other\\External\\OracleD
> river.zip");
> > 
> >     Path.PathElement pathElement2 = path.createPathElement();
> >     pathElement2.setPath(
> >  
> > 
> "C:\\Projects\\JavaFramework\\Source\\Other\\External\\log4j-1
> .2.8.jar");
> >     /*
> >     Path.PathElement pathElement3 = path.createPathElement();
> >     pathElement3.setPath("C:\\j2sdkee1.3.1\\bin");
> >     */
> > 
> >     sqlExec.setClasspath(path);
> >     sqlExec.setDriver(driver);
> >     sqlExec.setUrl(url);
> >     sqlExec.setUserid(userName);
> >     sqlExec.setPassword(password);
> >     sqlExec.setOutput(new File(outputFile));
> > 
> >     if(delimiter != null){
> >       sqlExec.setDelimiter(delimiter);}
> >     if(autoCommit != null){
> >         if(YES.equals(autoCommit)){
> >           sqlExec.setAutocommit(true);}
> >         else{
> >           sqlExec.setAutocommit(false);}
> >     }
> >     sqlExec.execute();
> >   }
> > 
> >  //
> >  public static void main(String[] args){
> >     SQLTaskWrapper sqlTaskWrapper = new SQLTaskWrapper();
> >  }
> > 
> >  public SQLTaskWrapper(){
> > 
> >   sqlFile = "C:/test.sql";
> >   driver = "oracle.jdbc.driver.OracleDriver";
> >   url = "jdbc:oracle:thin:@10.128.0.11:1521:odindia1";
> >   userName = "ENTERPRISE_REPOS";
> >   password = "erepos";
> >   outputFile = "C:/sqlRun.txt";
> >   delimiter = "/";
> >   autoCommit = YES;
> >   startAntSQLTask();
> > 
> >  }
> > 
> > }
> > 
> > 
> > Regards,
> > Ashish
> 
> 
> **********************************************************************
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please notify
> the system manager.
> 
> This footnote also confirms that this email message has been swept by
> MIMEsweeper for the presence of computer viruses.
> 
> www.mimesweeper.com
> **********************************************************************
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message