JDBC connection Issues

K

Ken

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?
 
T

Thomas Kellerer

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
 
K

Ken

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.
 
A

Arne Vajhøj

Ken said:
Sorry I should have mentioned that I do have db2jcc_license_cu.jar...


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
 
K

Ken

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).
 
K

Ken

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.
 
A

Arne Vajhøj

Ken said:
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
 
K

Ken

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.
 
A

Arne Vajhøj

Ken said:
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
 
M

Martin Gregorie

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.
 
A

Arne Vajhøj

Martin said:
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
 
R

Roedy Green

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
 
M

Martin Gregorie

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..
 
A

Arne Vajhøj

Martin said:
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
 
K

Ken

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());
}
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top