Hi,
 I'm using ant 1.6.5. I'm trying to run sql files in a row using SQLExec task.
The problem i am facing is that when execute  the task the sql files run and 
database and tables are created but at the same time in the console getting the 
exception like below:

sql:
[run_script] connecting to jdbc:mysql://localhost/sqltask
[run_script] Loading org.gjt.mm.mysql.Driver using a cached AntClassLoader.
[run_script] Opening PrintStream to output file C:\bishw\temp\log.txt
[run_script] Executing file: C:\bishw\temp\bishwakarma.sql
[run_script] SQL:  CREATE DATABASE bishwakarma123
[run_script] Failed to execute:  CREATE DATABASE bishwakarma123
[run_script] java.sql.SQLException: General error: Can't create database 
'bishwakarma123'. Database
exists

But there was no database named 'bishwakarma123' befor run.


My sql file looks like :

CREATE DATABASE bishwakarma123;

USE bishwakarma123;

--
-- Table structure for table `admin_user`
--

CREATE TABLE admin_user (
  user_id varchar(25),
  password varchar(25) ,
  PRIMARY KEY  (user_id)
) TYPE=InnoDB;



Can any one say me why i am getting such error and how it can be solved.

And another thing i want to know

How can i get the exact sequence of execution of sql files in the fileset?

Am i bound to give an existing database in the connection url? Otherwise it 
gives UNKNOWN Database error while connecting. It's o.k. if there is no such 
database then how can it connect to the database. Is there any way to use the 
same database in the connection url as is in the sql file which i want to run 
and here it is 'bishwakarma123'.


My simple Code snippet:

Project p = new Project();
                p.setName("execute_script");
                p.setDefault("sql") ;
                p.setBasedir(".");
               
                Target sql = new Target();
                sql.setName("sql");           
               
                Path class_path = new Path(p);
                
class_path.setPath("C:/jakarta-tomcat-5.0.27/webapps/bishwakarma/WEB-INF/lib/mm.mysql-2.0.2-bin.jar");
                SQLExec sqlexec = new SQLExec();
                sqlexec.setProject(p);
                sqlexec.setTaskName("run_script");
                sqlexec.setOwningTarget(sql);
                FileSet fs = new FileSet();
                fs.setDir(new File(temp_dir));
                fs.setIncludes("test1.sql test2.sql");
                sqlexec.addFileset(fs);
                sqlexec.setClasspath(class_path);
                sqlexec.setDriver("org.gjt.mm.mysql.Driver");
                sqlexec.setUrl("jdbc:mysql://localhost/sqltask");
                sqlexec.setUserid("root");
                sqlexec.setPassword("");
                sqlexec.init();
                sqlexec.execute();
               
                sql.addTask(sqlexec);
               
                p.addTarget(sql);

Thanks && Regards

Subir
       
---------------------------------
 Forgot the famous last words? Access your message archive online. Click here.

Reply via email to