0

I have written a Java program that is executed on an iSeries AS400. Within that program, I use a JDBC connection to the same machine to query data from the files like

select *
from xyzcapad.myFile
where lastName = 'Max'

The same file name and structure (not data!) exist in multiple libraries because we have multiple environments on our AS400 and each has its own default libraries.

So when I now start the program and run it in the environment that is using library xyzcapad, all works well. But if I run it in another env., how can I tell my program to use the other default library for that table?

1 Answer 1

1

When you are using JDBC, you can use the SET SCHEMA statement to select a library like this:

set schema xyzcapad;

Then execute your sql like this:

select *
  from myFile
  where lastName = 'Max';

Notice the table name is not qualified. In that case it will use the default schema which was set using the set schema statement above.

EDIT

Here my final code that got it working:

    public void connectAS400(){
        as400 = new AS400("my.company.com","user","password");
        AS400JDBCDataSource datasource = new AS400JDBCDataSource(as400);

//      datasource.setLibraries("xyzcapad");
        datasource.setTranslateBinary(true);
        datasource.setNaming("system");
        try {
            connection = datasource.getConnection();
        } catch (Exception e) {
            System.err.println(e);
        }

    }
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks but actually I needed something to retrieve the information in what environment I am currently in the first place. I figured that when using the AS400 objects and it's datasource, the API takes care of that automatically :)
I was going to suggest system naming which defaults to using the library list, but then I saw your edit and accepted that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.