This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes COBOL-DB2 SQLCODE handling vs Java Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "COBOL-DB2 SQLCODE handling vs Java Query" Watch "COBOL-DB2 SQLCODE handling vs Java Query" New topic
Author

COBOL-DB2 SQLCODE handling vs Java Query

rexian
Greenhorn

Joined: May 02, 2000
Posts: 25
I am with COBOL background. I am very used to check...
EVALUATE TRUE
WHEN SQLCODE = 0
......
WHEN SQLCODE = +100
......
WHEN OTHER
......
END-EVALUATE
What I am wondering is how to check for SQLCODEs in JAVA? Is there any way to check that? Or there is no need to? Moreover, I am going nuts with SQLCODE= 100 situation, ie, when no rows are retrieved from the database.
I am new to JAVA. Could you guys please help me?
Thanks,
Rex

------------------
Successful people in this world are those who get up and look for the circumstances they want. If they can't find them, they make them.


<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR><B>Successful people in this world are those who get up and look for the circumstances they want. If they can't find them, they make them.</B><HR></BLOCKQUOTE>
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
It Is A New World, A new Way To Think, A New Way To Code!
I have been a mainframe developer for over 15 years!
<pre>
// Proff of Concept
// Basic Example OF How JAVA1.2, JDBC2.0, DB2 Work Together
// sqlsel1 is a standard sql query
// sqlsel2 is a java stored procedure sql query
// Author: monty6 mireland1@mediaone.net

import java.sql.*;// java sql classes
public class JdbcTest {
public static void main(String args[]) {
try {
// load jdbc type 2 db2 driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

// con - connect driver manager
// 1. manages all jdbc connection
// 2. driver manager: jdbc.db2
// 3. connection datebase: " " DSNT is a DB2 sub-system
// 4. userid: " " USERID
// 5. password: " " PASSWORD
Connection con =
DriverManager.getConnection("jdbc:db2 SNT", "USERID", "PASSWORD");
// sql statement - create object to hold sql query
Statement stmt = con.createStatement();
// sql statement - define query
String sqlsel1 = "select * from dbname.tbname;";
// sql statement - execute query
ResultSet rs = stmt.executeQuery( sqlsel1 );
// sql statement - process query result set
while ( rs.next() ) {
String col1 = rs.getString("partition_nbr");
String col2 = rs.getString("as_of_date");
String col3 = rs.getString("reporting_date");
System.out.println( col1 + col2 + col3 );
} // end of while
// con statement - define query
String sqlsel2 =
"select * from dbname.tbname where partition_nbr > ? ;";
// con statement - prepare java store procedure statement
PreparedStatement con_stmt = con.prepareStatement( sqlsel2 );
// con statement - pass parm to java store procedure statment
// parm position = 1
// parm value = 05
con_stmt.setString( 1, "05" );
// con statement - execute java store procedure
ResultSet con_rs = con_stmt.executeQuery();
// con statement - process query result set
while ( con_rs.next() ) {
String col1 = con_rs.getString("partition_nbr");
String col2 = con_rs.getString("as_of_date");
String col3 = con_rs.getString("reporting_date");
System.out.println( col1 + col2 + col3 + "*" );
} // end of while
}// end of try block

// load driver
catch(ClassNotFoundException e) {
System.out.println("ClassNotFoundException!!!: " + e);
}
// sql sqlcode
catch(SQLWarning e) {
System.out.println("SQL_CODE !!!: " + e);
}
// sql class
catch(SQLException e) {
System.out.println("SQL_CLASS !!: " + e);
}// end of catch block(s)

}// end of main
}// end of class JdbcTest
</pre>
Hope This Helps, Monty6
[This message has been edited by monty6 (edited August 02, 2000).]
[This message has been edited by monty6 (edited August 02, 2000).]
rexian
Greenhorn

Joined: May 02, 2000
Posts: 25
Thanks a bunch.
 
GeeCON Prague 2014
 
subject: COBOL-DB2 SQLCODE handling vs Java Query