JDBC connection Issues

Discussion in 'Java' started by Ken, Apr 6, 2009.

  1. Ken

    Ken Guest

    I am looking for validation, I am very new to JDBC. However the issue
    could be with the server... In which case a recommendation to a more
    appropriate forum would be welcome.

    Anyways my first question is: Am I really using a type 4 driver?

    Here is my trimmed down source (it compiles fine btw) which is the
    root of my problems:
    ##################################################
    //!NOTE: I MUST HAVE db2jcc4.jar in my class path which I do.
    import java.sql.*;

    public class Main {
    public static void main(String[] args) throws ClassNotFoundException
    {
    //For type 4 Driver:
    //Class.forName("com.ibm.db2.jcc.DB2Driver");

    // Type 4 driver url
    String url = "jdbc:db2j:net://192.168.10.17/DBNAME";

    try
    {
    //Connect to a database .getConnection(url, uname, psswrd)
    Connection conn = DriverManager.getConnection(url, "myUsername",
    "myPasswd");
    System.out.println("I am here!");
    }
    catch (SQLException e)
    {
    System.out.println("SQL Exception: ");
    System.err.println(e.getMessage());
    }
    }
    }

    ##################################################

    When Compiled I receive the following error:
    SQL Exception:
    [jcc][t4][2043][11550][4.0.100] Exception java.net.ConnectException:
    Error opening socket to server /192.168.10.17 on port 1,527 with
    message: Connection refused. ERRORCODE=-4499, SQLSTATE=08001

    Now maybe I need to do something with the server, which is an AS400...
    and the DB is DB2.
    but I was wondering why if I uncomment the line after "//For type 4
    Driver:"
    AND change String url = "jdbc:db2j:net://192.168.10.17/AERIS170";
    to
    String url = "jdbc:db2://192.168.10.17/AERIS170";
    I get this Error:
    SQL Exception:
    [jcc][t4][10109][10354][4.0.100] The version of the IBM Universal JDBC
    driver in use is not licensed for connectivity to QAS databases.
    To connect to this server, please obtain a licensed copy of the IBM
    DB2 Universal Driver for JDBC and SQLJ.
    An appropriate license file db2jcc_license_*.jar for this target
    platform must be installed to the application class path.
    Connectivity to QAS databases is enabled by any of the following
    license files: [ db2jcc_license_cisuz.jar ]. ERRORCODE=-4472,
    SQLSTATE=42968

    Anyone out there knowledgeable about the AS400 and JDBC?
     
    Ken, Apr 6, 2009
    #1
    1. Advertising

  2. Ken wrote on 07.04.2009 00:24:
    > Now maybe I need to do something with the server, which is an AS400...
    > and the DB is DB2.
    > but I was wondering why if I uncomment the line after "//For type 4
    > Driver:"
    > AND change String url = "jdbc:db2j:net://192.168.10.17/AERIS170";
    > to
    > String url = "jdbc:db2://192.168.10.17/AERIS170";
    > I get this Error:
    > SQL Exception:
    > [jcc][t4][10109][10354][4.0.100] The version of the IBM Universal JDBC
    > driver in use is not licensed for connectivity to QAS databases.
    > To connect to this server, please obtain a licensed copy of the IBM
    > DB2 Universal Driver for JDBC and SQLJ.
    > An appropriate license file db2jcc_license_*.jar for this target
    > platform must be installed to the application class path.
    > Connectivity to QAS databases is enabled by any of the following
    > license files: [ db2jcc_license_cisuz.jar ]. ERRORCODE=-4472,
    > SQLSTATE=42968


    Well the error message says it all: add the db2jcc_license_xx.jar to your
    classpath, and the connection should work.

    I have only used these with DB2 on Linux, but it's the same jar files as far as
    I can tell.

    Thomas
     
    Thomas Kellerer, Apr 6, 2009
    #2
    1. Advertising

  3. Ken

    Ken Guest

    > Well the error message says it all: add the db2jcc_license_xx.jar to your
    > classpath, and the connection should work.


    Sorry I should have mentioned that I do have db2jcc_license_cu.jar...

    > I have only used these with DB2 on Linux, but it's the same jar files as far as
    > I can tell.
    >
    > Thomas


    Anyways there are two errors which I have listed, the first one looks
    like I am almost there but the connection has been refused... from a
    little searching it looks like "db2jcc_license_cisuz.jar" is at a
    cost. The frustrating thing is someone wrote a VB program that
    connects to the same server just fine so I don't think I need to pay
    for a license, or software that contains the JAR.
     
    Ken, Apr 6, 2009
    #3
  4. Ken

    Arne Vajhøj Guest

    Ken wrote:
    >> Well the error message says it all: add the db2jcc_license_xx.jar to your
    >> classpath, and the connection should work.

    >
    > Sorry I should have mentioned that I do have db2jcc_license_cu.jar...
    >
    >> I have only used these with DB2 on Linux, but it's the same jar files as far as
    >> I can tell.

    >
    > Anyways there are two errors which I have listed, the first one looks
    > like I am almost there but the connection has been refused... from a
    > little searching it looks like "db2jcc_license_cisuz.jar" is at a
    > cost.


    I believe that:
    cu = AIX, Linux, Windows
    cisuz = OS/400, MVS (they are i and z/OS today)

    The last is supposed to come with DB2 Connect and
    DB2 Enterprise Server Edition.

    I would guess that you have it somewhere.

    If not then try and call your IBM sales rep
    and ask for it - you paid for an iSeries system
    and now you need to connect to it.

    Arne
     
    Arne Vajhøj, Apr 7, 2009
    #4
  5. Ken

    Ken Guest

    > I believe that:
    >    cu = AIX, Linux, Windows
    >    cisuz = OS/400, MVS (they are i and z/OS today)
    >
    > The last is supposed to come with DB2 Connect and
    > DB2 Enterprise Server Edition.
    >
    > I would guess that you have it somewhere.
    >
    > If not then try and call your IBM sales rep
    > and ask for it - you paid for an iSeries system
    > and now you need to connect to it.
    >
    > Arne


    My machine (the machine I am making the connection from) is a linux
    machine... the host an AS/400e is running AIX (I think).
     
    Ken, Apr 7, 2009
    #5
  6. Ken

    Ken Guest

    > My machine (the machine I am making the connection from) is a linux
    > machine... the host an AS/400e is running AIX (I think).


    It is probably IBM i that it is running... Although my employer
    vehemently denies there being an OS (another issue all together)...
    All I know is that it loves CL commands.
     
    Ken, Apr 7, 2009
    #6
  7. Ken

    Arne Vajhøj Guest

    Ken wrote:
    >> My machine (the machine I am making the connection from) is a linux
    >> machine... the host an AS/400e is running AIX (I think).

    >
    > It is probably IBM i that it is running... Although my employer
    > vehemently denies there being an OS (another issue all together)...
    > All I know is that it loves CL commands.


    See if you can get the iSeries box admin to look for the
    DB2 install CD - it may have that jar file.

    If it fails then try IBM.

    Arne
     
    Arne Vajhøj, Apr 7, 2009
    #7
  8. Ken

    Ken Guest

    On Apr 6, 5:56 pm, Arne Vajhøj <> wrote:
    > Ken wrote:
    > >> My machine (the machine I am making the connection from) is a linux
    > >> machine... the host an AS/400e is running AIX (I think).

    >
    > > It is probably IBM i that it is running...  Although my employer
    > > vehemently denies there being an OS (another issue all together)...
    > > All I know is that it loves CL commands.

    >
    > See if you can get the iSeries box admin to look for the
    > DB2 install CD - it may have that jar file.
    >
    > If it fails then try IBM.
    >
    > Arne


    Okay I will do. Thank you. I'll get back if that jar resolves this.

    So the license jar is for the host? Oh I guess that does make
    sense... here I was thinking it was for the client for some reason
    (linux)... although the idea of any license information on the client
    side seems odd to me, why would the server not handle such details? I
    suppose all programming makes as much sense as the programmers/
    managers decide it will.

    A while back I found connecting with JDBC to both a MySQL DB and an
    ACCESS DB to be a breeze, so far my experience with DB2 and IBM
    documentation incredibly frustrating. I like how Sun very good
    tutorials and make few very assumptions and then provide you with very
    technical documentation once you know the lay of the land. I don't
    mind dense writing, believing K&R to be one of the best written books
    ever.
     
    Ken, Apr 7, 2009
    #8
  9. Ken

    Arne Vajhøj Guest

    Ken wrote:
    > On Apr 6, 5:56 pm, Arne Vajhøj <> wrote:
    >> Ken wrote:
    >>>> My machine (the machine I am making the connection from) is a linux
    >>>> machine... the host an AS/400e is running AIX (I think).
    >>> It is probably IBM i that it is running... Although my employer
    >>> vehemently denies there being an OS (another issue all together)...
    >>> All I know is that it loves CL commands.

    >> See if you can get the iSeries box admin to look for the
    >> DB2 install CD - it may have that jar file.
    >>
    >> If it fails then try IBM.

    >
    > Okay I will do. Thank you. I'll get back if that jar resolves this.
    >
    > So the license jar is for the host? Oh I guess that does make
    > sense... here I was thinking it was for the client for some reason
    > (linux)... although the idea of any license information on the client
    > side seems odd to me, why would the server not handle such details? I
    > suppose all programming makes as much sense as the programmers/
    > managers decide it will.


    It is for the client. But the client needs a different
    license depending on which server it is talking to.

    > A while back I found connecting with JDBC to both a MySQL DB and an
    > ACCESS DB to be a breeze, so far my experience with DB2 and IBM
    > documentation incredibly frustrating. I like how Sun very good
    > tutorials and make few very assumptions and then provide you with very
    > technical documentation once you know the lay of the land. I don't
    > mind dense writing, believing K&R to be one of the best written books
    > ever.


    I don't think the DB2 manual is that bad.

    And newer version of DB2 are quite good.

    Arne
     
    Arne Vajhøj, Apr 7, 2009
    #9
  10. On Mon, 06 Apr 2009 16:43:01 -0700, Ken wrote:

    >> My machine (the machine I am making the connection from) is a linux
    >> machine... the host an AS/400e is running AIX (I think).

    >
    > It is probably IBM i that it is running... Although my employer
    > vehemently denies there being an OS (another issue all together)... All
    > I know is that it loves CL commands.
    >

    In that case its running OS/400.



    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, Apr 7, 2009
    #10
  11. Martin Gregorie wrote:
    > On Mon, 06 Apr 2009 16:43:01 -0700, Ken wrote:
    >>> My machine (the machine I am making the connection from) is a linux
    >>> machine... the host an AS/400e is running AIX (I think).

    >> It is probably IBM i that it is running... Although my employer
    >> vehemently denies there being an OS (another issue all together)... All
    >> I know is that it loves CL commands.
    >>

    > In that case its running OS/400.


    Yep.

    But that was what he wrote.

    Since "OS/400" was renamed to "i5/OS" and that was renamed
    to "IBM i".

    I am not following IBM OS'es that closely so they may have
    changed the name a couple of times extra without me noticing.

    Arne
     
    Arne Vajhøj, Apr 8, 2009
    #11
  12. Ken

    Roedy Green Guest

    On Mon, 6 Apr 2009 15:24:59 -0700 (PDT), Ken <>
    wrote, quoted or indirectly quoted someone who said :

    >Anyways my first question is: Am I really using a type 4 driver?


    I don't think you can tell from the text of your JDBC connect. You
    must read the docs from the vendor. I have collected some stats on
    driver type at
    http://mindprod.com/jgloss/jdbcvendors.html#JDBCVENDOR
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    "At this point, 29 percent of fish and seafood species have collapsed - that is,
    their catch has declined by 90 percent. It is a very clear trend, and it is accelerating.
    If the long-term trend continues, all fish and seafood species are projected to collapse
    within my lifetime -- by 2048."
    ~ Dr. Boris Worm of Dalhousie University
     
    Roedy Green, Apr 8, 2009
    #12
  13. On Tue, 07 Apr 2009 19:43:49 -0400, Arne Vajhøj wrote:

    > Martin Gregorie wrote:
    >> On Mon, 06 Apr 2009 16:43:01 -0700, Ken wrote:
    >>>> My machine (the machine I am making the connection from) is a linux
    >>>> machine... the host an AS/400e is running AIX (I think).
    >>> It is probably IBM i that it is running... Although my employer
    >>> vehemently denies there being an OS (another issue all together)...
    >>> All I know is that it loves CL commands.
    >>>

    >> In that case its running OS/400.

    >
    > Yep.
    >
    > But that was what he wrote.
    >

    Huh? OS/400 was never renamed to AIX which is what I was responding to,
    as in "the host an AS/400e is running AIX"

    > I am not following IBM OS'es that closely so they may have changed the
    > name a couple of times extra without me noticing.
    >

    Same here. I haven't used OS/400 for a loong time, but I remember finding
    it surprisingly nice to use once I'd got used to it. Pretty much bullet-
    proof too: I don't recall ever seeing it crash..


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, Apr 8, 2009
    #13
  14. Martin Gregorie wrote:
    > On Tue, 07 Apr 2009 19:43:49 -0400, Arne Vajhøj wrote:
    >> Martin Gregorie wrote:
    >>> On Mon, 06 Apr 2009 16:43:01 -0700, Ken wrote:
    >>>>> My machine (the machine I am making the connection from) is a linux
    >>>>> machine... the host an AS/400e is running AIX (I think).
    >>>> It is probably IBM i that it is running... Although my employer
    >>>> vehemently denies there being an OS (another issue all together)...
    >>>> All I know is that it loves CL commands.
    >>>>
    >>> In that case its running OS/400.

    >> Yep.
    >>
    >> But that was what he wrote.
    >>

    > Huh? OS/400 was never renamed to AIX which is what I was responding to,
    > as in "the host an AS/400e is running AIX"


    Oh - sorry.

    I was referring to the "It is probably IBM i that it is running...".

    Arne
     
    Arne Vajhøj, Apr 8, 2009
    #14
  15. Ken

    Ken Guest

    Thank you for your help.

    I wanted to follow up with my solution in case someone else stumbles
    on this thread.

    I used JTOpen from http://jt400.sourceforge.net/

    With it everything is straight forward no license files, no DB connect
    to deal with...
    If anyone stumbles on this thread simply make sure jt400.jar is in the
    class path available from the link provided.

    and use the following code as a guide:

    import java.sql.*;

    public class Main
    {

    public static void main(String[] args){
    // define login info for as400666
    String host = "192.168.1.111/DBName";
    String user = "username";
    String pwd = "password";

    try{
    // make sure driver exists
    Class.forName("com.ibm.as400.access.AS400JDBCDriver");
    }catch(Exception e){
    System.out.println(e.toString());
    }

    try{
    // create a new connection from driver
    Connection con = DriverManager.getConnection("jdbc:as400://" +
    host, user, pwd);
    // create new statement from connection
    java.sql.Statement stmt = con.createStatement();

    // sql
    //String sql="SELECT FNAME,LNAME FROM LIBRARY.FILE FETCH FIRST
    10 ROWS ONLY";
    String sql="SELECT * FROM CO02DT.DTNAME FETCH FIRST 10 ROWS
    ONLY";

    // execute query
    ResultSet rs = stmt.executeQuery(sql);

    // loop through results
    while(rs.next()){
    System.out.println( rs.getString(1) + " " +
    rs.getString(2) + " " +
    rs.getString(3)) ;
    }
    //System.out.println(rs);
    // close connection
    con.close();

    }catch(Exception e){
    System.out.println(e.toString());
    }
    }
    }
     
    Ken, Apr 15, 2009
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith Wansbrough

    Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver

    Keith Wansbrough, Aug 16, 2004, in forum: Java
    Replies:
    0
    Views:
    769
    Keith Wansbrough
    Aug 16, 2004
  2. Betty
    Replies:
    1
    Views:
    9,886
    Juha Laiho
    May 21, 2005
  3. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,279
    robert
    Feb 11, 2006
  4. Bruce
    Replies:
    4
    Views:
    767
    Bjorn Abelli
    Mar 25, 2006
  5. Lew
    Replies:
    0
    Views:
    526
Loading...

Share This Page