Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2012
    Posts
    44

    Unanswered: JDBC/Java connect to DB2 on z/OS

    Hi

    I am trying to connect from Eclipse/Java (Windows) to DB2 on mainframe (z/OS)

    Code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    
    public class ConnectDB2 {
    	public static void main(String[] args) {
    		Connection connection = null;
    		ResultSet resultSet = null;
    		Statement statement = null;
    
    		try {
    			Class.forName("com.ibm.db2.jcc.DB2Driver");
    			connection = DriverManager.getConnection(
    					"jdbc:db2://host.db2-mainframe.net:5020/dbname",
    					"username", "password");
    
    			statement = connection.createStatement();
    
    			resultSet = statement
    					.executeQuery("SELECT ...");
    
    			while (resultSet.next()) {
    				System.out.println("xxx:"
    						+ resultSet.getString("xxx"));
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			try {
    				resultSet.close();
    				statement.close();
    				connection.close();
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    	}
    }
    error message

    Code:
    com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException: [jcc][t4][2057][11264][4.11.77] The application server rejected establishment of the connection.
    An attempt was made to access a database, dbname, which was either not found or does not support transactions. ERRORCODE=-4499, SQLSTATE=08004
    	at com.ibm.db2.jcc.am.gd.a(gd.java:319)
    	at com.ibm.db2.jcc.am.gd.a(gd.java:365)
    	at com.ibm.db2.jcc.t4.ab.u(ab.java:1674)
    	at com.ibm.db2.jcc.t4.ab.n(ab.java:536)
    	at com.ibm.db2.jcc.t4.ab.a(ab.java:343)
    	at com.ibm.db2.jcc.t4.ab.a(ab.java:115)
    	at com.ibm.db2.jcc.t4.b.m(b.java:1242)
    	at com.ibm.db2.jcc.t4.b.b(b.java:1113)
    	at com.ibm.db2.jcc.t4.b.d(b.java:696)
    	at com.ibm.db2.jcc.t4.b.c(b.java:682)
    	at com.ibm.db2.jcc.t4.b.a(b.java:367)
    	at com.ibm.db2.jcc.t4.b.<init>(b.java:307)
    	at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:214)
    	at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:460)
    	at java.sql.DriverManager.getConnection(DriverManager.java:582)
    	at java.sql.DriverManager.getConnection(DriverManager.java:185)
    	at ConnectDB2.main(ConnectDB2.java:53)
    java.lang.NullPointerException
    	at ConnectDB2.main(ConnectDB2.java:76)
    thanks for helping

  2. #2
    Join Date
    Apr 2012
    Posts
    1,034
    Provided Answers: 18
    On your Windows machine, which db2-component(s) have you installed, and what are the db2-version and db2-fixpack of those windows-based components?

  3. #3
    Join Date
    Feb 2012
    Posts
    44
    Quote Originally Posted by db2mor View Post
    On your Windows machine, which db2-component(s) have you installed, and what are the db2-version and db2-fixpack of those windows-based components?
    do I need to install something expect importing the java class?

    For example to connect to Oracle db, I don't need to install Oracle Client. It's pure Java connection.

  4. #4
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    db2 connect license file..
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  5. #5
    Join Date
    Apr 2012
    Posts
    1,034
    Provided Answers: 18
    In addition to a jar file containing the db2 type-4 driver (available in the db2 run time client) you also need to have db2jcc_license_cisuz.jar. Full details are in the IBM knowledge centre for your version of db2.

  6. #6
    Join Date
    Feb 2012
    Posts
    44
    Quote Originally Posted by przytula_guy View Post
    db2 connect license file..
    I added db2jcc_license_cisuz.jar to the classpath. Still same issue.
    Attached Thumbnails Attached Thumbnails Ry1iVg3.png  

  7. #7
    Join Date
    Apr 2012
    Posts
    1,034
    Provided Answers: 18
    works fine for me. Something you are not telling us about your environment...

  8. #8
    Join Date
    Feb 2012
    Posts
    44
    thank you guys. Found the error

    IBM ERRORCODE=-4499, The application server rejected establishment of the connection. - United States

    Problem(Abstract)

    Attempt to connect to a database using Type 4 JCC driver fails with the following exception:

    java.sql.SQLException:
    [jcc][t4][2057][11264][3.53.95] The application server rejected establishment of the connection. An attempt was made to access a database, <database name>, which was either not found or does
    not support transactions. ERRORCODE=-4499,
    SQLSTATE=08004 DSRA0010E: SQL State = 08004, Error Code = -4,499



    Cause
    Using DCS DB alias or local alias name of the database in the connection string will cause this error.
    my dbname was lowercase, but I need uppercase.

    thanks guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •