I need to use the cqlsh copy to command in my java application. (copy keyspace.table (column1, column2) to 'path';)
So, is there a way to execute a cqlsh file with that command or just execute the command in the java code?
Thanks!
Because COPY is cqlsh command, not CQL expression, then only way is to launch cqlsh from the Java code via -e command line switch, for example, you can use Apache Commons Exec library, but you'll need to have cqlsh installed on the machine where your Java program runs.
P.S. COPY not always the best way - DataStax has DSBulk utility that is heavily optimized for performant data loading and unloading.
Related
we are working on a java 8 standalone project, and we need to extract a query log from another application (an .exe), we were using the ODBC tracing to get the logs (manually for each run), but now we need to get them automatically (the other application querys variates depending of a .txt that we edit during the execution).
We need to know if there is a way to start the odbc tracing using java code, or with Runtime code (with cmd). What kind of alternatives we have?.
Setting the Trace key value in the registry should start tracing. Be sure to turn it off when not needed. Here is a PowerShell script to do that.
Push-Location
Set-Location HKCU:\Software\ODBC\ODBC.INI\ODBC
Set-ItemProperty . Trace "1"
# Set-ItemProperty . TraceDll "C:\WINDOWS\system32\odbctrac.dll"
# Set-ItemProperty . TraceFile "$Env:USERPROFILE\SQL.LOG"
Pop-Location
If it must be run from a cmd.exe shell, put the script into traceon.ps1 and use the following command. If you have already configured your machine to be able to run PowerShell scripts, then the -ExecutionPolicy Bypass is not needed.
powershell -NoProfile -ExecutionPolicy Bypass -File traceon.ps1
Is it possible to run an entire, large, powershell script in a java application without calling it externally by launching a powershell process with the -file parameter? (passing it via the encodedcommand parameter won't work either because of the commandline lenght limitation).
I.e. is there a java library that enables you to paste your powershellscript inside your java app and run it?
I currently embed the powershellscript inside the java application and write it to disk, but I'm looking for a fileless approach.
Since you want to pass a large program, piping from the Java program to the PS script is more suitable than using the command line or environment variables. Since I don't know too much Java and don't have it installed, I'll simulate it from the PS command line in the snippet below. Your Java program would read the lines of the program from a list or some other suitable data structure (whereas this example reads it from the file system). I did see hits on google for piping from Java to an externally executed command.
cat my.ps1|
powershell -command {$scr="";foreach ($line in $input){$scr+=$line+"`n"} echo bxb $s cxc}
After your PS stub has received the program rather than echo it, it would execute it: iex $scr.
If you need to pass parameters from Java to PS you could either pipe them along with the program (for example as lines of code that set global variables) or they could be global variables set in stub code. Other, more complex, variations are possible.
Is there any function to import and export all collections of mongodb database using java driver.? like there is mongodump and mongorestore using command prompt.
The short answer is no. These commands can be invoked only from command line. You might consider to fetch all the data from all collections but its expected to be slow.
You can read a discussion around this here.
mongodump --host localhost --port 27017 --db sample
It exacts with folder as dump with database name sample
mongorestore --db sample --verbose d:/dump/sample/
(same answer as here)
recently I've started a project called mongodbdump-java-wrapper to wrap mongodump.exe and mongorestore.exe mongodb executable from java.
You could clone it from : github project. This project includes integration tests (a way to know how implement backup/restore).
Well as of now, Mongo Java driver does not support this.
You can try invoking the mongoimport and mongorestore commands from Java Runtime. Like
Runtime.getRuntime().exec("mongoimport -d <dbname> -h <>..");
I have a large number of source commands to execute. So I want to write some Java code to do this. Is there a way to do this in Java?
source command is like this:
mysql> source /home/liova/download/tpch/queries/Q1.sql;
You can execute any shell command using Runtime.exec:
Runtime.exec("mysql db_name < /home/liova/download/tpch/queries/Q1.sql");
You can use Runtime class to execute any commands in java. It executes the command as seperate process.
I have implemented a task in Hive.
But now I need to call a Shell Script which I have written for importing the tables in Hive from SQL Server using SQOOP. In that Shell Script I have written a SQOOP Command for importing the tables in HIve.
I tried to call a Shell Script in one of the Demo Application but as the Program runs no action taken place. I just see the blank console.
Do I need to do something extra in case of Hive?
Please help me out from this.
Thanks.
Try to run /bin/sh /home/....TableToExport.sh.
This explicitly defines the shell that interprets your script. This should work.
If it does not work try to simplify your command line. Start from running simple command like ls or hostname. When it works try to execute something more complicated.
Generally it should work. You are on the right way.