File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Using AS400JDBCDriver() and AS400() together Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using AS400JDBCDriver() and AS400() together" Watch "Using AS400JDBCDriver() and AS400() together" New topic
Author

Using AS400JDBCDriver() and AS400() together

Brennen smith
Ranch Hand

Joined: Dec 29, 2010
Posts: 33
I am using IBM Toolbox for Java(jt400.jar) to connect to my AS400 server. I am a little confused. All examples I have found use this typical format to set up the initial connection.


I end up with connectdb which is an instance of the AS400JDBCDriver class(See description of classes below). I am trying to use the AS400() class to get more information from my connection such as the username of the logged in user. This involves defining a new version of AS400(). My question is how do I connect the AS400 class to my connection... OR do i need to create my connection in a different way in order to be able to use the AS400 Class. Thank you in advance.




AS400JDBCDriver
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/rzahh/javadoc/com/ibm/as400/access/AS400JDBCConnection.html
AS400
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/rzahh/javadoc/com/ibm/as400/access/AS400.html
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Well, as I see it from my quick once-over of the pages you linked, AS400JDBCDriver has a getSystem() method which returns an AS400 object. So I think you should use that one rather than creating a new one which has nothing to do with the JDBC driver object at all.

If you were wondering how to get an AS400JDBCDriver object, I would recommend casting the Connection object you get in that code to AS400JDBCDriver.
Brennen smith
Ranch Hand

Joined: Dec 29, 2010
Posts: 33
Well and I looked into that exact option but when I try and use getSystem() method i do not see it!


The reason I believe my connection class connectdb is and AS400JDBCDricer class is during debuging I see this...



So why does it not show up... I know i'm using the newest version of the IBM Toolbox? Am i missing an import?

Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Well, yeah, if you ask your IDE what are the members for the Connection type, it isn't going to tell you what are the members for the AS400JDBCDriver type. That's why I suggested doing the cast.
Brennen smith
Ranch Hand

Joined: Dec 29, 2010
Posts: 33
Alright I think I am following you. Forgive me for my ignorance but by casting do you mean something like...



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

No, I mean casting as described in this tutorial.

(By the way I don't have that URL memorized, or even in my browser bookmarks. The way I found it was by using java casting tutorial as my web search keywords. In general if you want to learn about feature X in Java then "java X tutorial" is a good choice for keywords.)
Brennen smith
Ranch Hand

Joined: Dec 29, 2010
Posts: 33
Was actually looking at that exact tutorial. So to clarify...

Since connectdb is an instance of Connection I need to create a new Connection class, lets call it MyConnection, that extends both Connection and AS4000JDBCDriver?



Does this logic sound correct?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

No, you're completely off-track. The piece of the puzzle you're missing is this: Officially, the DriverManager.getConnection() class returns a Connection object. But in practice it returns an object which implements the Connection interface and which knows how to talk to an AS400 via JDBC. In other words, it returns an AS400JDBCDriver object.

So all you have to do is to cast the object you get from DriverManager.getConnection() to a variable of type AS400JDBCDriver. You don't have to write any more classes.

However this may all be a waste. I don't see why you have to do any of this business to find out what user ID is built into that connection; the user ID is one of the properties you put in when you create the connection. In other words you should already have that information somewhere.
Brennen smith
Ranch Hand

Joined: Dec 29, 2010
Posts: 33
I think I understand what you are saying. I though that was what I was doing with the code below.



I tried... but none of the Connection class methods are working anymore. I apologize for my ignorance can you give me an example of how I would cast this class.




The way my connection works now I am using a built in login window. So i never get a chance to capture the login information I saw that the AS400() class has the ability to get the user id so that is why I am trying to get access to the methods of the AS400 class. If there is an easier way using the sql connection class to get the user id of the logged in account, please let me know. I am trying to work this out on my own but nothing seems to get me any closer.

Thanks for your help.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

There's only one possible place to cast in those two lines of code. Didn't you read the tutorial about casting?
Brennen smith
Ranch Hand

Joined: Dec 29, 2010
Posts: 33
Got it. I have never casted objects that way... I am somewhat new to Java and OOP, I appreciate your help and patience. I am actually excited, I can think of other ways I can use this in existing programs.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Brennen smith wrote:I am actually excited, I can think of other ways I can use this in existing programs.


Great! That's one of the questions a good programmer asks: What else can I do with this new thing I just learned?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using AS400JDBCDriver() and AS400() together