mysql -e not working from Java
Posted by: AR Mahdi
Date: April 27, 2010 06:48AM

Hi All,

I was trying to create CSV files for every table using the "Select * into OUtfile "file" ..." but it didnt really work as I wanted to create these files where the java code is running so that It can access, instead it creates the files on the host where the query is run So i was left wioth not other option but to run mysql -e from commandline thru the java program.. I am using this little routine:

String command2= "mysql -hmyhost -uusername -pmypass DMyDB -e'" + sql + "'" ;

Process child = rt.exec(command2);

ps = new PrintStream(tableSqlFile);
InputStream in = child.getInputStream();
int ch;

while ((ch = in.read()) != -1) {
ps.write(ch);

// System.out.write(ch); //to view it by console
}

Now it doesnt run it with errors instead it gives me the help options for Mysql.
I think the error is with the -e option. I tried doing it with -e\" "+sql+\"" or with single quotes but it just doesnt work. I also tried it this way :

String command= "mysql --user=" + user + " --password="
+ pwd + " --host=" + sourceHost + " --execute=\" "
+ sql + "\" "+dbName;

It doesnt wokr either. I would really appreciate if any one can tell me what I am doing wrong here.. sql is a simple select * from tablename

Just above this routine. I did the exact same thing mysqldump command and it works fine. it works because it doesnt have any -e or --execute option..

Thanks in advance
ali

Options: ReplyQuote


Subject
Written By
Posted
mysql -e not working from Java
April 27, 2010 06:48AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.