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.
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.
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.
(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.)
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?
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.
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.
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.