aspose file tools*
The moose likes JDBC and the fly likes java DB2 program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java DB2 program " Watch "java DB2 program " New topic
Author

java DB2 program

Amar Naik
Ranch Hand

Joined: Sep 26, 2003
Posts: 43
i log in my mainframe environment using my user id and password ..
After that i go to QMF and fire my DB2 queries...

I want to read the DB2 tables , through my JAVA program..can anybody please guide on how i can od the connection to the DB2 database and what drivers are required..i am using Java 1.4

i know about connection through Oracle..
so if anybody can help me can you please let me know about DB2
Amar Naik
Ranch Hand

Joined: Sep 26, 2003
Posts: 43
any help on this
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30938
    
158

Amar,
Connecting to db2 is the same as connecting to Oracle. But for mainframe, I think you need to use db2 connect.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
IBM has many ways to connect distributed systems to mainframes. Your mainframe DB2 administrators ought to know some of the options. DB2 connect rings a bell, but nowadays I would not be shocked if you could set up a client-side alias for it just like an AIX or Windows hosted database.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Amar Naik
Ranch Hand

Joined: Sep 26, 2003
Posts: 43
am trying to run a java db2 program. my db2 is in os/390.
below is the code
public class T4DB2Connect {
public static void main(String[] args) {


try {
// load the DB2 Driver
System.out.println("1" );
Class.forName("COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver");
// establish a connection to DB2
System.out.println("2" );
Connection db2Conn = DriverManager.getConnection("jdbc b2://host ip address/db name","user id","passwd");
System.out.println("3" );
Statement st = db2Conn.createStatement();
System.out.println("4" );
String query =
"SELECT A.BJB_SCSJB_NM FROM CRYWTBT.TBSUC_JOBS A ,CRYWTBT.TBPRD_JOBS B, CRYWTBT.TBJOB_FREQ C WHERE A.BJB_NM ='CLR606AM' AND A.BJB_NM=B.BJB_NM AND B.BJB_NM=C.BJB_NM";
ResultSet resultSet = st.executeQuery(query);
System.out.println("Job " + "\tAverage Salary");
System.out.println("-----" + "\t--------------");
while (resultSet.next()) {
String jobType = resultSet.getString(1);
System.out.println(jobType );
}
resultSet.close();
st.close();
db2Conn.close();
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
}

the error is
1
2
com.ibm.db2.jcc.b.DisconnectException: Execution failed due to a distribution pr
otocol error that caused deallocation of the conversation. A DRDA Data Stream S
yntax Error was detected. Reason: 0x3
at com.ibm.db2.jcc.a.ab.l(ab.java:1214)
at com.ibm.db2.jcc.a.ab.c(ab.java:363)
at com.ibm.db2.jcc.a.ab.v(ab.java:1447)
at com.ibm.db2.jcc.a.bb.a(bb.java:39)
at com.ibm.db2.jcc.a.b.e(b.java:1232)
at com.ibm.db2.jcc.a.b.b(b.java:1147)
at com.ibm.db2.jcc.a.b.q(b.java:931)
at com.ibm.db2.jcc.a.b.a(b.java:702)
at com.ibm.db2.jcc.a.b.(b.java:305)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:162)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at T4DB2Connect.main(T4DB2Connect.java:16)


when i tried to change the jdbc connection to
Connection db2Conn = DriverManager.getConnection("jdbc b2os390://host ip address/db name","user id","passwd");
the error

com.ibm.db2.jcc.b.SqlException: Deprecated DB2 OS/390 protocol not supported by
T4: jdbc b2os390://host ip address/db name
Use protocol jdbc b2:
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:98)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at T4DB2Connect.main(T4DB2Connect.java:16)
 
 
subject: java DB2 program