Example of database connection string DB2/400

2010-04-22
2013-06-03
  • Didier HONORE
    Didier HONORE
    2010-04-22

    Hello

    Who have example of connection string for a DB2/400 database?

    I have tried:

    Driver class Name :   com.ibm.as400.access.AS400JDBCDriver
    Connection info :  as400://<IP ADDRESS>
    Database Name : mydb
    User Name : myuser
    password : mypassword

    and I have the message :

    java.lang.ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver

    Any ideas??

    Thanks

     
  • Jim Menard
    Jim Menard
    2010-04-22

    You will probably have better luck getting an answer on the mailing list. You need to join the list to ask a question there, but more people read the mailing list than these forums.

     
  • Jim Menard
    Jim Menard
    2010-04-22

    Also, this may not be a connection string error. Are you sure the driver's jar file is on your classpath?

     
  • Didier HONORE
    Didier HONORE
    2010-04-26

    In the datavision.bat file, I have:

    set DVCLASSPATH=C:\Program Files (x86)\Java\jre6\lib:C:\Program Files (x86)\IBM\Client Access\jt400\lib

    Is it Ok??

    Thanks

     
  • Jim Menard
    Jim Menard
    2010-04-26

    You will need double quotes around the paths that have spaces in them. Also, on Windows the path separator is a semicolon, not a colon. Try this:

    set DVCLASSPATH="C:\Program Files (x86)\Java\jre6\lib";"C:\Program Files (x86)\IBM\Client Access\jt400\lib"

    Note that these paths won't pick up any jar files in those lib directories, just class files. That's just how Java classpaths work. If you need to add jar files you'll have to add each one separately.

     
  • Didier HONORE
    Didier HONORE
    2010-04-26

    with :

    set DVCLASSPATH="C:\Program Files (x86)\Java\jre6\lib";"C:\Program Files (x86)\IBM\Client Access\jt400\lib"

    I get :

    C:\Program Files (x86)\DataVision>datavision.bat
    Exception in thread "main" java.lang.NoClassDefFoundError: Files
    Caused by: java.lang.ClassNotFoundException: Files
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: Files.  Program will exit.

     
  • Try encasing the whole value in quotes:

    set DVCLASSPATH="C:\Program Files (x86)\Java\jre6\lib;C:\Program Files (x86)\IBM\Client Access\jt400\lib"

     
  • Didier HONORE
    Didier HONORE
    2010-05-18

    sorry for delay for the reply

    same error:

    C:\Program Files (x86)\DataVision>datavision.bat
    Exception in thread "main" java.lang.NoClassDefFoundError: Files
    Caused by: java.lang.ClassNotFoundException: Files
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: Files.  Program will exit.

     
  • Jim Menard
    Jim Menard
    2010-05-18

    Hmm…Java class paths don't find jar files inside directories. (They do file class files inside directories, but not jar files). So I think that you will have to add every jar file you need that is in each lib directory to the class path individually.

     
  • > Exception in thread "main" java.lang.NoClassDefFoundError: Files

    To me, this suggests a quoting issue of some kind, and that the string "Files" is being found as part of

      C:\Program Files (x86)

    and something misinterpreted it as a class name.

    Regarding

    > Java class paths don't find jar files inside directories

    True, although the distributed datavision.bat file contains code to enumerate them and add them… at least those in the .\lib directory underneath datavision.bat.  I wrote that code :)

    dhonore: What exactly does

      datavision.bat -v

    output?  This will tell us exactly what java command is being run.

    Also, instead of editing the datavision.bat file, please try just putting all the .jar files needed for your database into the .\lib directory and using the datavision.bat file exactly as it comes with DataVision 1.2.0.  This really should work, there is no need to modify it.  The relevant comment in datavision.bat says:

    DVCLASSPATH must contain paths to all needed classes for DV,
    separated by semicolons.  All .jar files under lib
    below the directory the .bat file is in are automatically added.
    If you need others, either drop them in that directory, or add them
    here manually (dropping them in the directory is better!).

    Please do what it suggests (drop them into that directory), or, if you really have good reason to,  include the path to each additional .jar file (not just the path to where they are, but a path including the name of each additional .jar file) to DVCLASSPATH

    As the comment suggests "dropping them in the  directory is better".  As you are discovering (!), it is better because it avoids you having to wrestle with editing .bat files, quoting issues, spaces in paths, etc. entirely.

    Hoping this helps,

    Jonathan

     
  • Didier HONORE
    Didier HONORE
    2010-07-21

    Soory for the delay.
    (sometimes, difficult to manage several projects at the same time)

    here the result of datavision.bat -v :

    C:\Program Files (x86)\DataVision>datavision.bat -v
    java -classpath "C:\Program Files (x86)\DataVision\lib;C:\Program Files (x86)\Ja
    va\jre6\lib;C:\Program Files (x86)\IBM\Client Access\jt400\lib";C:\Program Files
    (x86)\DataVision\lib\asm.jar;C:\Program Files (x86)\DataVision\lib\bsf.jar;C:\P
    rogram Files (x86)\DataVision\lib\charsets.jar;C:\Program Files (x86)\DataVision
    \lib\commons-logging.jar;C:\Program Files (x86)\DataVision\lib\DataVision.jar;C:
    \Program Files (x86)\DataVision\lib\deploy.jar;C:\Program Files (x86)\DataVision
    \lib\derby.jar;C:\Program Files (x86)\DataVision\lib\iText.jar;C:\Program Files
    (x86)\DataVision\lib\javaws.jar;C:\Program Files (x86)\DataVision\lib\jcalendar.
    jar;C:\Program Files (x86)\DataVision\lib\jce.jar;C:\Program Files (x86)\DataVis
    ion\lib\jruby.jar;C:\Program Files (x86)\DataVision\lib\jsse.jar;C:\Program File
    s (x86)\DataVision\lib\jt400.jar;C:\Program Files (x86)\DataVision\lib\jt400Mri_
    fr.jar;C:\Program Files (x86)\DataVision\lib\jt400Servlet.jar;C:\Program Files (
    x86)\DataVision\lib\jui400.jar;C:\Program Files (x86)\DataVision\lib\junit.jar;C
    :\Program Files (x86)\DataVision\lib\management-agent.jar;C:\Program Files (x86)
    \DataVision\lib\plugin.jar;C:\Program Files (x86)\DataVision\lib\poi.jar;C:\Prog
    ram Files (x86)\DataVision\lib\resources.jar;C:\Program Files (x86)\DataVision\l
    ib\rt.jar;C:\Program Files (x86)\DataVision\lib\sqlitejdbc.jar;C:\Program Files
    (x86)\DataVision\lib\tes.jar;C:\Program Files (x86)\DataVision\lib\tesMri_fr.jar
    ;C:\Program Files (x86)\DataVision\lib\uitools.jar;C:\Program Files (x86)\DataVi
    sion\lib\uitools_fr.jar;C:\Program Files (x86)\DataVision\lib\util400.jar;C:\Pro
    gram Files (x86)\DataVision\lib\x4j400.jar" -Dswing.aatext=true jimm.datavision.
    DataVision -v
    Exception in thread "main" java.lang.NoClassDefFoundError: Files
    Caused by: java.lang.ClassNotFoundException: Files
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: Files.  Program will exit.

    I have copied all the jar files from C:\Program Files (x86)\Java\jre6\lib and C:\Program Files (x86)\IBM\Client Access\jt400\lib to C:\Program Files (x86)\DataVision\lib

    Same error!

    Do you have another idea??

    Thanks

    Didier

     
  • Is that output from an unmodified datavision.bat file? 

    There seem to be three (3) double quote marks in the command being run.  This is obviously a problem, since they need to be in pairs!

    As a workaround for whatever quoting problem you are seeing, you could move the whole Datavision directory (and everything under it) to somewhere where there are no spaces in the path above it, perhaps to C:\datavision, and try running things from there.

    If I have a chance, I'll try running datavision.bat on a 64bit Windows machine and see if I can get it to fail in the same way with the 3 quote marks in the command.

    Jonathan

     
  • Didier HONORE
    Didier HONORE
    2010-07-22

    I have reinstalled datavision in c:\datavision

    my datavision.bat:

    @echo off
    rem datavision.bat - script to run Datavision under Windows with an appropriate
    rem                   classpath.  If first parameter is -v, will output java
    rem                   command line before running it.
    rem                   NOTE: This does NOT work under Windows 95/98/NT.
    rem                   It DOES work under Windows 2000/XP/Vista.

    setlocal
    setlocal ENABLEDELAYEDEXPANSION

    rem Find out drive and directory where this script is,
    rem so we can find the jar files underneath it.
    set SCRIPTPATH=%~d0%~p0

    rem DVCLASSPATH must contain paths to all needed classes for DV,
    rem separated by semicolons.  All .jar files under lib
    rem below the directory the .bat file is in are automatically added.
    rem If you need others, either drop them in that directory, or add them
    rem here manually (dropping them in the directory is better!).
    set DVCLASSPATH="C:\Program Files (x86)\IBM\Client Access\jt400\lib"
    rem Build the classpath
    for %%Y in ("%SCRIPTPATH%"lib\*.jar) do set DVCLASSPATH=!DVCLASSPATH!;%%Y
    rem Get rid of unwanted initial semicolon
    SET DVCLASSPATH=%DVCLASSPATH:~1%

    rem Output what we will execute, for debugging, if we have a -v switch
    if not "X-vX" == "X%1X" goto :endif
      shift
      echo java -classpath "%DVCLASSPATH%" -Dswing.aatext=true jimm.datavision.DataVision %*
    :endif

    rem Run the relevant Java code with the appropriate classpath
    java -classpath "%DVCLASSPATH%" -Dswing.aatext=true jimm.datavision.DataVision %*

    Result :

    C:\DataVision>datavision.bat -v
    java -classpath "C:\Program Files (x86)\IBM\Client Access\jt400\lib";C:\DataVisi
    on\lib\asm.jar;C:\DataVision\lib\bsf.jar;C:\DataVision\lib\commons-logging.jar;C
    :\DataVision\lib\DataVision.jar;C:\DataVision\lib\derby.jar;C:\DataVision\lib\iT
    ext.jar;C:\DataVision\lib\jcalendar.jar;C:\DataVision\lib\jruby.jar;C:\DataVisio
    n\lib\junit.jar;C:\DataVision\lib\poi.jar;C:\DataVision\lib\sqlitejdbc.jar" -Dsw
    ing.aatext=true jimm.datavision.DataVision -v
    Usage: java  class
               (to execute a class)
       or  java  -jar jarfile
               (to execute a jar file)

    where options include:
        -server       to select the "server" VM
        -hotspot      is a synonym for the "server" VM 
                      The default VM is server.

        -cp <class search path of directories and zip/jar files>
        -classpath <class search path of directories and zip/jar files>
                      A ; separated list of directories, JAR archives,
                      and ZIP archives to search for class files.
        -D<name>=<value>
                      set a system property
        -verbose
                      enable verbose output
        -version      print product version and exit
        -version:<value>
                      require the specified version to run
        -showversion  print product version and continue
        -jre-restrict-search | -jre-no-restrict-search
                      include/exclude user private JREs in the version search
        -? -help      print this help message
        -X            print help on non-standard options
        -ea
        -enableassertions
                      enable assertions
        -da
        -disableassertions
                      disable assertions
        -esa | -enablesystemassertions
                      enable system assertions
        -dsa | -disablesystemassertions
                      disable system assertions
        -agentlib:<libname>
                      load native agent library <libname>, e.g. -agentlib:hprof
                        see also, -agentlib:jdwp=help and -agentlib:hprof=help
        -agentpath:<pathname>
                      load native agent library by full pathname
        -javaagent:<jarpath>
                      load Java programming language agent, see java.lang.instrument

        -splash:<imagepath>
                      show splash screen with specified image

     
  • Didier HONORE
    Didier HONORE
    2010-07-22

    with rhe following datavision.bat file, datavision starts:
    @echo off
    rem datavision.bat - script to run Datavision under Windows with an appropriate
    rem                   classpath.  If first parameter is -v, will output java
    rem                   command line before running it.
    rem                   NOTE: This does NOT work under Windows 95/98/NT.
    rem                   It DOES work under Windows 2000/XP/Vista.

    setlocal
    setlocal ENABLEDELAYEDEXPANSION

    rem Find out drive and directory where this script is,
    rem so we can find the jar files underneath it.
    set SCRIPTPATH=%~d0%~p0

    rem DVCLASSPATH must contain paths to all needed classes for DV,
    rem separated by semicolons.  All .jar files under lib
    rem below the directory the .bat file is in are automatically added.
    rem If you need others, either drop them in that directory, or add them
    rem here manually (dropping them in the directory is better!).

    rem Build the classpath
    for %%Y in ("%SCRIPTPATH%"lib\*.jar) do set DVCLASSPATH=!DVCLASSPATH!;%%Y
    rem Get rid of unwanted initial semicolon
    SET DVCLASSPATH=%DVCLASSPATH:~1%

    rem Output what we will execute, for debugging, if we have a -v switch
    if not "X-vX" == "X%1X" goto :endif
      shift
      echo java -classpath "%DVCLASSPATH%" -Dswing.aatext=true jimm.datavision.DataVision %*
    :endif

    rem Run the relevant Java code with the appropriate classpath
    java -classpath "%DVCLASSPATH%" -Dswing.aatext=true jimm.datavision.DataVision %*

     
  • Didier HONORE
    Didier HONORE
    2010-07-22

    Now I have copied the jt400.jar files in C:\DataVision\lib

    I starts datavision:

    C:\DataVision>datavision.bat

    Now I create a database connection :

    driver class name: com.ibm.as400.access.AS400JDBCDriver
    connection info : as400://192.168.2.203
    Database name : libemrp
    Username : <user>
    Password : <password>

    Error :

    java.sql.SQLException: no suitable driver found for as400://192.168.2.203

    any godd ideas??

    Thanks for your help

     
  • OK.  At least now Datavision runs and is loading your .jar file :)

    > java.sql.SQLException: no suitable driver found for as400://192.168.2.203

    It looks like your AS400 JDBC driver does not know how to deal with that connection string.  I don't know if that really is the correct format for such strings expected by the com.ibm.as400.access.AS400JDBCDriver - at this point you really want help from someone who has used that driver before, or some example connection strings for it.

    Have you used this JDBC driver for AS400 before?  Are you sure that connection string is 100% perfectly correct?

    Based on http://www.javacamp.org/moreclasses/jdbc/jdbc.html#as400 I think you might want to try something closer to

      jdbc:as400://192.168.2.203/libemrp

    for the connection string, and leave the Database name: field empty.

    BUT I have never used this driver in my life… this is just a guess based on a quick Google search :)

    Jonathan

     
  • Didier HONORE
    Didier HONORE
    2010-07-22

    Now I am connected with the following string:

    com.ibm.as400.access.AS400JDBCDriver
    jdbc:as400://192.168.2.203/libemrp

    but I cannot enter SQL statment or select any tables!!
    (in the database menu)

    any ideas?,

    thanks