2
votes

What I'm trying to do: find a way to backup a DB2 database via a JDBC command/query. Here's the command that I've tested with the DB2 command-line program:

backup database dbName to C:\backup\db2

It works just fine on the command line, but when attempting to run it in either Data Studio or through a standalone JDBC program, it fails. Here's the JDBC exception message:

SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: backup database dbName to C:/;BEGIN-OF-STATEMENT;<values>

Data Studio complains about "JOIN" being expected instead of "dbName", and a few other things. I have yet to find any helpful documentation about DB2, which is why I came here.

Has anyone run into this before and figured out how to resolve the issue? Or is there something I've missed?

1
Have you een the official DB2 documentaiton? publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/…David
Yes I have, which is how I knew the syntax that works with the DB2 command-line tool. But unless I'm missing something on that page, there's no info that helps me with either Data Studio or JDBC.David Young
You probably have to do this in 2 steps. 1) Backup the DB2 database to the same system that the database resides on. 2) FTP the backup to your computer. I don't believe you can backup a DB2 database over JDBC.Gilbert Le Blanc
I'm okay with the backup being on the same box as the DB2 instance. Sorry, should've mentioned that up front. I just need to RUN the backup via JDBC.David Young

1 Answers

1
votes

Try using the admin_cmd procedure:

CALL SYSPROC.ADMIN_CMD('backup db mydatabase to c:\backup\db2\')

This will work also through the JDBC drivers.