Forums Register Login

Using AS400JDBCDriver() and AS400() together

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Alright I think I am following you. Forgive me for my ignorance but by casting do you mean something like...



+Pie Number of slices to send: Send
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.)
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
There's only one possible place to cast in those two lines of code. Didn't you read the tutorial about casting?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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?
Poop goes in a willow feeder. Wipe with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 8527 times.
Similar Threads
Java calls to RPG functions
Java + AS400 API
conversion from decimal to packed BCD
What is AS400 about?
NoClassDefFoundError
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:39:18.