How do I use mysqlimport? - java

Here is the command I am running using Runtime.getRuntime().exec() in Java:
mysqlimport --fields-terminated-by=, --lines-terminated-by="|" --local
--user=u --password=p DatabaseName
txtpath
Here is the error I get:
java.io.IOException: Cannot run program "mysqlimport": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at databaseCommunication.UploadThread.run(UploadThread.java:66)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
It seems like the problem should be that mysqlimport.exe is not installed or is not installed in the correct place, but I have tried downloading the mySQL utilities from http://dev.mysql.com/downloads/windows/installer/5.6.html and from https://dev.mysql.com/downloads/utilities/.
In order to make sure the problem was not that it could not find the file at "txtpath," I typed the full path into the command prompt, and the correct file was opened, so the error is definitely referring to mysqlimport.exe.
Googling my problem, the only threads I've been able to find refer to something called "Sqoop" which I am not familiar with, and they usually recommend downloading the mysql utilities.
For more context, I have been using BCP to upload data from a txt file to a sql server database, but now I need to do the same thing with mysql. If there is any way to use BCP (I'm pretty sure there isn't) or something else to bulk upload data from a local file I would be open to hearing that as well.
EDIT:
I am using Windows 8 on a remote desktop. I have manually added mysqlimport.exe to the PATH environment variable and it still gives the same error.

If you are on Windows, then try putting mysqlimport.exe as the command rather than just mysqlimport. If that still does not solve your problem, make sure that 'mysqlimport.exe' is in your PATH environment variable.

Related

Why can't I run a batch command from my java program? [duplicate]

This question already has answers here:
How do I run a batch file from my Java Application?
(12 answers)
Closed 8 years ago.
I'm trying to run a command from my java application. I get input from the user and run this line of code: Runtime.getRuntime().exec($userInput);. I've tried lots of simple commands, including "echo," "start chrome," and "rem." It seems that the only command that works is "cmd.exe," and I have no idea what that even does.
Commands such as "echo" generate this error:
java.io.IOException: Cannot run program "echo": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at me.Draconwolver.Main.runCmd(Main.java:119)
at me.Draconwolver.Main.main(Main.java:34)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 6 more
Feel free to ask me for more details.
Because echo, start, rem etc aren't executable programs. They are shell commands. Only the command shell undertstands them. You have to run them with
cmd /c echo
cmd /c start chrome
etc.

Running wordcount.jar on hadoop in windows using command line

I am trying to run a simple wordcount program on hadoop, but facing an error as below.
Exception in thread "main" java.io.IOException: Error opening job jar: /user/asiapac/bmohanty6/wordcount/wordcount.jar
at org.apache.hadoop.util.RunJar.main(RunJar.java:90)
Caused by: java.io.FileNotFoundException: \user\asiapac\bmohanty6\wordcount\wordcount.jar (The system cannot find the path specified)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at org.apache.hadoop.util.RunJar.main(RunJar.java:88)
I am using below command.
$ bin/hadoop jar /user/asiapac/bmohanty6/wordcount/wordcount.jar WordCount /user/asiapac/bmohanty6/wo
rdcount/input /user/asiapac/bmohanty6/wordcount/output
I am using Cygwin, hadoop-0.20.2 with pseudo node set up. I have also uploaded the wordcount.jar to my DFS. See below my DFS screenshot
I am able to run the same wordcount program in eclipse successfully. I have created the wordcount.jar file via eclipse as per this tutorial. I searched a lot in web but could not understand how to solve this. Please help me.
You need to add / before user:
bin/hadoop jar /user/asiapac/bmohanty6/wordcount/wordcount.jar WordCount /user/asiapac/bmohanty6/wordcount/input /user/asiapac/bmohanty6/wordcount/output
This makes them fully-qualified paths. If you omit / before user, Hadoop will search from the current directory.

java.lang.UnsatisfiedLinkError while calling a dll from java

I have a java programm which needs a .jar and a .dll file. If running the java programm from command line it works. Running it out of eclipse I get the following error:
java.lang.UnsatisfiedLinkError: com.osisoft.rdsa.RDSAChannel.GetDASVersion(J)S
at com.osisoft.rdsa.RDSAChannel.GetDASVersion(Native Method)
at com.osisoft.rdsa.RDSAChannel.<init>(RDSAChannel.java:58)
at com.osisoft.rdsa.NativeRDSA.create(NativeRDSA.java:185)
at com.osisoft.rdsa.NativeRDSA.create(NativeRDSA.java:127)
at com.osisoft.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:75)
at com.osisoft.jdbc.DriverExtension.connect(DriverExtension.java:121)
at com.osisoft.jdbc.Driver.connect(Driver.java:261)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at testclients.jtesterbase.JTesterBase.connect(JTesterBase.java:417)
at testclients.jtesterbase.JTesterBase.init(JTesterBase.java:182)
at testclients.jtesterbase.JTesterBase.main(JTesterBase.java:552)
what is the problem?
The .dll file is in C:\Windows\system\32\RDSAWrapper64.dll, so it has already be in the java.lang search path.
What environment changes between executing on console and executing in eclipse?
Has somebody some tips. I tried to fix it for hours.
Thanks so much for your help.

Open Excel from Java Application

If I am tring to open notepad from Java Application then it will open Notepad.But If I will try to open Excel then it is giving me exception.
try
{
Runtime.getRuntime().exec("excel");
}
catch (IOException e)
{
e.printStackTrace();
}
Following is Exception :
java.io.IOException: Cannot run program "excel": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at OpenNotepad.main(OpenNotepad.java:18)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
When I do start->Run->Excel then it will open excel.
If you are trying to use Java to open an Excel file, rather than just opening Excel, I suggest you use the Desktop API class: http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html
This class will use the default OS file handling mechanism, so it will use say MS Excel in Windows, and Open Office in Linux.
Runtime.getRuntime().exec("some command"); does the same as "some command" will do in cmd. So the solution for opening Excel you should try this.
try {
Runtime.getRuntime().exec("cmd /c start excel.exe");
} catch (IOException e) {
e.printStackTrace();
}
in the exec method give fuuly qualified path where your excel is installed and then try and RunTime is good but better to use ProcessBuilder
Runtime.getRuntime().exec() is the same thing as doing something from the command line.
In windows OS there is an environment variable set to C:\Windows\System32
all the exe of commands are in this path.
when I do following in cmd I get this.
C:\Users\bhaviksh>echo %PATH%
D:\oracle\product\10.2.0\client_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\
System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\MySQL
\MySQL Server 5.0\bin;C:\Program Files\cvsnt;C:\Program Files\TortoiseSVN\bin;C:
\maven\bin
Solution : use fully qualified name of exe file
Add microsoft office excel executable path
for eg:
If Directory C:\Program Files (x86)\Microsoft Office\Office14 has EXCEL.EXE then add C:\Program Files (x86)\Microsoft Office\Office14 to your classpath.
How to add to classpath Click here.
Once you are done, restart your IDE, your program should work.

How to clear console in java (Using netbeans)

I am using jdj 1.7,netbeans 7 versions. I wrote a program that's working fine. Now i want to clear the console window after many outputs in the console. I tried the below line Runtime.getRuntime().exec("cls"); also tried with exec("clear"). But i am getting these errors:
Exception in thread "main" java.io.IOException: Cannot run program "cls": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:431)
at java.lang.Runtime.exec(Runtime.java:328)
at Periodical.main(Book.java:88)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
What's the problem here. How can i clear the console? Thank you
If you want to keep it portable you might want to use a library like jcurses. That will save you the trouble of having to detect what kind of console/terminal you are on and will give you a lot of other nice features like cursor and color control.

Categories