Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

COBOL-DB2 SQLCODE handling vs Java Query

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a bunch.
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic