Reputation: 375
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?
Upvotes: 0
Views: 1059
Reputation: 11473
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);
}
}
Upvotes: 1