Run MySql from Java failed -


i'm trying run mysql command java process using process exec

the code:

string s = "mysql -h192.168.0.1 -u user -password db_name-e \"select * table\" system.out.println(s); process p = r.exec(s); p.waitfor(); 

when i'm running sql query command line works great, java process ' usage: mysql [options] [database]... mysql options.

without -e parameter seems work, no error of course nothing happens. in win& machine works great, not on deploy linux machine.

any ideas i'm doing wrong?

example of java using mysql:

import java.sql.connection; import java.sql.drivermanager; import java.sql.sqlexception; import java.sql.statement; import java.sql.resultset;  // assume conn created jdbc connection (see previous examples)  statement stmt = null; resultset rs = null;  try {     stmt = conn.createstatement();     rs = stmt.executequery("select foo bar");      // or alternatively, if don't know ahead of time     // query select...      if (stmt.execute("select foo bar")) {         rs = stmt.getresultset();     }      // resultset .... } catch (sqlexception ex){     // handle errors     system.out.println("sqlexception: " + ex.getmessage());     system.out.println("sqlstate: " + ex.getsqlstate());     system.out.println("vendorerror: " + ex.geterrorcode()); } {     // idea release     // resources in finally{} block     // in reverse-order of creation     // if no-longer needed      if (rs != null) {         try {             rs.close();         } catch (sqlexception sqlex) { } // ignore          rs = null;     }      if (stmt != null) {         try {             stmt.close();         } catch (sqlexception sqlex) { } // ignore          stmt = null;     } } 

taken here.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -