Want a syntax where I can give my DB2 details like server name,user name,password and sql file which want to execute using batch file.
I found syntax like sqlplus,sqlcmd for oracle and sql server respectively but no luck for 'DB2'.
Pls help me in it.
Note that this is about DB2 on the IBM i platform (see comments).
For Windows, from a command prompt, type db2cmd, then from there run e.g. db2 connect to YOUR_DATABASE user YOUR_USER_ID then e.g. db2 -tf filename.sql
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0002036.html
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0010410.html
IBM i Access Client Solutions (which I assume you have available to you, this part of its functionality being free of charge) has a command line option for this, e.g.
java -jar acsbundle.jar /SYSTEM=MYAS400 /PLUGIN=rss /file=\mysqlscript.sql /autorun=1
See ftp://ftp.software.ibm.com/as400/products/clientaccess/solutions/GettingStarted_en.html for more information (specifically section 9.1.31).
I think, this might help somebody in future, who is looking for solution,Just make sure you have Db2 Client installed & add following snippet in your batch file.
SET DB2CLP=DB20FADE
runas /noprofile /user:db2admin "db2cmd -c db2 create database MyDatabase && db2 connect to MyDatabase && db2 -tvmf db2_create_tables.sql"
I too faced many issues but after some research i came up with this solution, i hope it will help you/someone.
Well, I guess you didn't really search.
Db2 has several command line interfaces that can be and are used for batch processing. Clpplus even offers Oracle-like syntax support and compatibility. There is even a tool named db2batch that allows to process statements with lots of options.
Related
I am really new to Batch and DB2 and got little time to explore much about them. I just want to know how it is possible for a batch program to pass a value/s to a db2 file so I can manipulate my database.
I found several suggestions but none of them worked. Here's my batch codes so far:
Rem This is db2execute.bat
#echo off
db2cmd -c -w -i db2 -tf INSERT.db2 id=1
PAUSE
My .db2 file on the other hand:
CONNECT TO SAMPLEDB;
INSERT INTO TB1 VALUES('$(ID)');
I would really appreciate some kind help. Thanks.
At the present time, in the shipping versions of Db2-LUW, the CLP (command line processor) does not directly support parameters in script files in the style that your question suggests.
If your product-type and version offers the clpplus command, then you can instead try using the Oracle sqlplus style for passing parameters on the command line and referencing those parameters in your script. See the Db2 and Oracle documentation for details .
I'm a novice trying to install Postgresql on Cygwin as a service. I have been following the steps listed in this URL: http://www.smartpixie.com/wiki/Tech/CygwinPostgreSQL.twiki.html
Everything was working fine until I got to the step where I had to create a user and a database for myself, in my /usr/sbin directory the "createuser" file exists but the "createdb" file does not. So, as suggested by the steps, I attempted to connect to the database as the SYSTEM user and then create the database/user roles later. However, I come across this error whenever I try to connect to the database.
$ psql -U SYSTEM postgres
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Any help is appreciated, thanks.
First, I would recommend against running PostgreSQL over Cygwin. There isn't a real use case I can see since there is now a native port and Cygwin ends up adding quite a bit of overhead to things like IPC calls. You won't get good performance out of it, and I can't actually think of any case where cygwin would be a better fit than mingw for c-language stored procedures. So please question whether this is really a requirement and explore other options first.
Now if you still need to do so, the process isn't easy, but is documented at http://www.postgresql.org/message-id/3DC76EA4.7090503#usa.net
Basically you have to install the ipc service first, then use cygrunsrv to create a Windows service for PostgreSQL dependent on it. Then you can run net start ipc-daemon and then net start postgresql
I installed db2 client in my system for personal use. I am not able to understand from where to create the database so that i can create tables on that db and play around with sql queries as of now.
This is totally related to my personal use and learning purpose.
Please inform how to create a dummy database and play around with it with db2 client?
Regards,
Are you on Windows? Are you using DB2 Express-C? I'm assuming you are, since you say this is for personal work.
After you have the DB2 binaries installed, you should have been prompted with the "DB2 First Steps" application, where you could have the application go through a GUI to create the database for you. If you missed it, you should be able to find it in your start menu with Start -> Programs -> IBM DB2 -> DB2COPY1 (Default) -> Set-up Tools -> First Steps.
If you prefer the command line, you can use the following:
First, determine if your installation created a default instance (on Windows, this will be called DB2) by using the db2ilist command. In the DB2 Command Window, if you're not on the instance you want to create a database in, you can switch with the following command:
set db2instance=DB2
Be sure to not include spaces around the equal sign.
Now, in order to create a database in the current instance, you use this command:
db2 create database mydatbase
For further reading, IBM has produced a Getting Started ebook, and I would highly recommend you check it out!
The DB2 client is just that - a client only. It does not include the database engine.
To create a database you have to install the server. The server includes the client portions.
I have a MSSQL database, which contains Unicode (utf8) data. My workstation is linux (currently Ubuntu) and looking for a tool to work with mssql database I found SQSH.
The problem is - when I select data in the sqsh console I get jibberish instead of unicode characters. Using switch "-J utf8" or "-J utf-8" didn't change anything.
The question is - how to set up sqsh to work with utf-8 data?
If it is not possible, do you know any alternative tools usable from linux for work with mssql databases filled with utf-8 data. I need to execute all kinds of T-SQL, run previsously prepared SQL script files, and pipe out results for processing afterwards. A good GUI (open source) could also be used, not limited to shell clients.
Are you using freetds with sqsh? If you are, edit your freetds.conf to set the charset.
http://www.freetds.org/userguide/localization.htm
Use Azure Data Studio to avoid data troubleshooting issue. it is a great SSMS alternative for Linux.
If you need command line tool I suggest to use official sqlcmd from mssql-tools.
It is available for all major Linux distributions including Ubuntu.
Connecting with sqlcmd
Another shell tool is mssql-cli
Features
Mssql-cli is a new and interactive command line tool that provides the
following key enhancements over sqlcmd in the Terminal environment:
T-SQL IntelliSense
Syntax highlighting
Pretty formatting for query results, including Vertical Format
Multi-line edit mode
Configuration file support
I had the same problem and it seems it has nothing to do with charchters encoding, but the problem was there are control character, unprintable characters, in the script.
I removed them from the sql script and everything works fine.
I'm looking for a command line tool to generate DDL for both tables and indexes (nothing more complicated is needed) for some Sybase tables in databases that I take care of. I have access to GUI tools for viewing the individual DDLs, and I could cut and paste them, but I would like something that will go through all the tables in a database and generate some nice text files that I can get checked into CVS.
I tried using a tool called ddlgen, which was provided by Sybase, but it just threw exceptions like this:
bash-3.00# ./ddlgen -SdatabaseServer:4100 -Uusername -PsecretPassword -TDB -NdatabaseName
U64: null: databaseName.dbo.firstTable
U64: null: databaseName.dbo.firstTable
at com.sybase.ddlgen.container.UserTableContainer.getDependentDDL(UserTableContainer.java:1065)
at com.sybase.ddlgen.container.UserTableContainer.open(UserTableContainer.java:1364)
at com.sybase.ddlgen.container.UserTableMetaContainer.open(UserTableMetaContainer.java:94)
at com.sybase.ddlgen.container.DDLBaseContainer.load(DDLBaseContainer.java:76)
at com.sybase.ddlgen.container.DatabaseContainer.addChildren(DatabaseContainer.java:552)
at com.sybase.ddlgen.container.DatabaseContainer.open(DatabaseContainer.java:104)
at com.sybase.ddlgen.container.DatabaseMetaContainer.open(DatabaseMetaContainer.java:114)
at com.sybase.ddlgen.DDLThread.run(DDLThread.java:89)
which wasn't very helpful. I keep thinking that there must be a nice Perlish way to do this, but I don't know what that would be.
You can also use the Perl-based dbschema.pl
http://www.isug.com/Sybase_FAQ/ASE/section9.html#9.3.2
use below command to get deffination
defncopy -P tester1 -S sqppdb2 -U pmestr -D ppdb2 -o tab4 ppdb2..tab4
Thanks
Download an evaluation version of Embarcadero DBArtisan and use its extract feature to get the DDL out.
You can turn Logging on in DBArtisan (Logfile ->Log SQL) and then see what SQL it's sending to Sybase to get the table DDL. Copy and paste the SQL in the logfile to a script that you run from the command line and that might work.
Apologies in advance if you are not using Windows...DBArtisan is Windows-only.
Another way of doing this is MyGeneration a code generator (like CodeSmith but open source) which uses templates to create code. That code could be anything you like - Sql, C# etc. I use Sql Server and I've used some of the freely available templates to create DDL as you specify, and automagically create NHibernate Mapping files too - brilliant.
ddlgen will give you what you require and works very well. You seem to be having an enviroment issue with Java. Try again and post the error that you have in it's entirety.