How to create sh script which will run SQL file on CentOS without sqlplus lib - sql

I'd need to create a sh script, which will connect to Oracle DB and then execute a SQL file.
The problem is that sqlplus is not installed on that Cent-OS machine and most probably it won't be installed either.
Is there a way how to do this?

You can easily install Oracle Instant Client including sqlplus executable ("Free to download, deploy and distribute").
See
https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html

If some java version is installed on the server, you can create a simple class that will connect to oracle DB via JDBC, load the sql script and execute it.
Create and compile java class
Upload class file, sql script + oracle_driver (jar file) (https://www.oracle.com/database/technologies/jdbcdriver-ucp-downloads.html)
Execute the java program

You can’t. You need to install oracle client which include sqlplus or sqlloader.
Or you can use Python and library Cx_Oracle, but you still need sqlclient to connect to database.
If you don’t want to install oracle client, you can use external table to load data to database or some etl tool.

Related

Shut down HSQLDB in server mode from the shell

How can I stop a running HSQLDB server instance from the shell (e.g. as part of a shell script)?
Try the following. Replace dbname with the name of your database and change credentials if necessary, and adjust the classpath to your system as needed:
java -cp $CLASSPATH:/usr/share/java/hsqldbutil.jar:/usr/share/java/hsqldb.jar "org.hsqldb.cmdline.SqlTool" --inlineRc=url=jdbc:hsqldb:hsql://localhost/dbname,user=SA,password= --sql="SHUTDOWN;"
If your distro comes with a shell script wrapper for SQL Tool, you can shorten that as:
hsqldb-sqltool --inlineRc=url=jdbc:hsqldb:hsql://localhost/dbname,user=SA,password= --sql="SHUTDOWN;"
Instead of using --inlineRc you can also build an rcfile with the parameters you need and specify that.

Run sql file for a specific derby database

Using the ij tool and Apache Derby, is it possible to execute an sql file in a single command line?
In other words, is it possible to supply the connection string to ij?
At the moment I'm doing it with several steps:
java org.apache.derby.tools.ij
connect 'jdbc:derby://someserver:1527//databases/timesheets';
run 'my_file.sql';
It is possible to run ij using properties, see examples here.
Use the following command:
java -Dij.database="jdbc:derby://someserver:1527//databases/timesheets" org.apache.derby.tools.ij my_file.sql

Installing UDFs in Netezza (Aginity)

I'm trying to use the GROUP_CONCAT() UDF in a Netezza query but I have no idea how to install the function into my database! I've downloaded the c++ code and there's an installer in the folder but I don't know how to run that!
I've been googling it for about a day now with no luck. I'm using a Windows computer and am running Netezza through Aginity.
Would anyone be able to help me out?
Thanks in advance,
Conor
UDFs are installed through a command line interface on the Netezza host, and not through SQL. You will need to sftp the source code to the host, connect with an SSH tool (e.g. putty or the Aginity SSH client under Tools->SSH Terminal), and run the install script from there. Your database login will not work for logging into the host. You may have to work with your administrator to get access.
Here is an exmaple of innstalling the c++ version of GROUP_CONCAT into a database called TESTDB.
[nz#netezza group_concat]$ ls -1
GroupConcat.cpp
GroupConcatSep.cpp
install
[nz#netezza group_concat]$ ./install testdb
CREATE AGGREGATE
Created uda
Done
CREATE AGGREGATE
Created uda
Done

Alternatives to sqlcmd/best practice

I have created a sql query that updates certain tables taking a CSV file as the input.
I want my co-workers to be able to execute this query as easily as possible. At first, I thought a batch file using sqlcmd was the best solution.
The end product works on my computer, because I have SSMS installed, but no other computer is able to properly launch the batch file.
What is the best way for my end-users to run an sql query? I have thought/researched these solutions:
-Install SSMS or the required tools(don't want each user to have to do this.)
-Install Psexec tools to allow for remote batch launching (also don't like this.)
Is there a better way?
Check SQLS*Plus from www.memfix.com - works the best.
Why don't you create a C-Sharp or VB.Net program that executes the proc and distribute the program to your users?
You don't have to install all of SMS. You can just install SQLServer2008CmdLnUtilsx86.msi for SQL 2008 or go here to get SQLCMD for SQL 2012. http://www.microsoft.com/en-us/download/details.aspx?id=36433. Just be aware that if you install SQLCMD in a bat file and then attempt to use SQLCMD after installing it in that same bat file you have to specify full path to SQLCMD because PATH value is loaded at time bat was started and SQLCMD was not yet available at that time.

How can I execute SQL scripts using TeamCity?

I´m new with TeamCity and I don´t know how to run SQL scripts with it.
Is the way simply selecting the path of those scripts in a Command Line Build Runner ?
I´m pretty lost.
Regards.
In a command line build step:
Command executable: c:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe
Command parameters: -S <server> -i <path_to_file> <== Note: that's a capital -S!
You may need to change the 100 to something else, depending on the version of the SQL Server tools that you have installed on the build agent.
I believe that SQLCMD / SQLPLUS / MYSQL are available as standalone executables which you can install on the TeamCity server.
Microsoft® SQL Server® 2008 R2 Feature Pack
Oracle SQL Plus
MYSQL Command Line
However, without knowing your actual SQL Platform this may differ and the provider should have an alternative.
You can then create a Command Line Runner to call the executeable and pass in the parameters required, which are further explained here.
Using the sqlcmd Utility
Using sqlplus utility
If you are looking at doing Database Migrations as part of your CI process, it would also be worth checking out RoundhousE