Re: [U2] JDBC - ClassPath - Victory

2010-03-24 Thread Brutzman, Bill
Ben:

Thanks for the follow-up.  I appreciate it.

--Bill

-Original Message-
From: u2-users-boun...@listserver.u2ug.org
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Ben Souther
Sent: Tuesday, March 23, 2010 5:34 PM
To: U2 Users List
Subject: Re: [U2] JDBC - ClassPath - Victory

Glad it's working.

Tip:  You should always put the con.close() statement in a finally
block.
The close method itself can throw an exception so it needs to be in a
nested try/catch.

Putting in in a finally block insures that come Hello or high water the
connection gets closed.
One of the most common causes for memory leaks in JDBC applications is
the build up of unclosed database connections.


Connection con = null;
try{
// establish connection and do stuff
}catch(Exception e){
// deal with any problems
}finally{
try{
con.close();
}catch(Exception ignored){}
}







On Mar 23, 2010, at 3:33 PM, Brutzman, Bill wrote:

 The following code works ok...
 
 Thanks to all those who responded especially John, Jeff, Bruce, 
 Charles, Ben, and Mike.
 
 --Bill
 
 import java.sql.*;
 
 public class Uni_101 {
 
public static void main(String[] args) {
try {
 
try {
   Class.forName(com.ibm.u2.jdbc.UniJDBCDriver); 
}
catch(Exception x){
   System.out.println( Here  + x );
} 
  String url = 
 jdbc:ibm-u2://192.168.0.102/SHIPPING;
  String  userid
 = ups;
  String passWord  = 
 brown;
 
Connection con = DriverManager.getConnection(url, userid, 
 passWord);
 
Statement stmt = con.createStatement();
 
  String sql = select @ID, NAME, 
 CITY, STATE from PACKSLIPS.X;
ResultSet rs = stmt.executeQuery(sql);
 
int i = 1;
while (rs.next()  i  6)
{
System.out.println(\nRecord + i + :);
System.out.println(\...@id : \t + rs.getString(1));
System.out.println(\tNAME :\t + rs.getString(2));
System.out.println(\tCITY :\t + rs.getString(3));
System.out.println(\tSTATE :\t + rs.getString(4));
i++;
}
 
rs.close();
stmt.close() ;
System.out.println(\n\t*--- QUERY test is done successful
 ---*\n);
 
}
catch (SQLException e ) {
System.out.println(e);
}
}
 
 }
 ___
 U2-Users mailing list
 U2-Users@listserver.u2ug.org
 http://listserver.u2ug.org/mailman/listinfo/u2-users
 

___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users
___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users


Re: [U2] JDBC - ClassPath - Victory

2010-03-23 Thread Brutzman, Bill
The following code works ok...

Thanks to all those who responded especially John, Jeff, Bruce, Charles,
Ben, and Mike.

--Bill

import java.sql.*;

public class Uni_101 {

public static void main(String[] args) {
try {

try {
Class.forName(com.ibm.u2.jdbc.UniJDBCDriver); 
}
catch(Exception x){
System.out.println( Here  + x );
} 
  String url
= jdbc:ibm-u2://192.168.0.102/SHIPPING;
  String  userid
= ups;
  String
passWord  = brown;

Connection con = DriverManager.getConnection(url, userid,
passWord);
 
Statement stmt = con.createStatement();

  String sql = select @ID, NAME,
CITY, STATE from PACKSLIPS.X;
ResultSet rs = stmt.executeQuery(sql);

int i = 1;
while (rs.next()  i  6)
{
System.out.println(\nRecord + i + :);
System.out.println(\...@id : \t + rs.getString(1));
System.out.println(\tNAME :\t + rs.getString(2));
System.out.println(\tCITY :\t + rs.getString(3));
System.out.println(\tSTATE :\t + rs.getString(4));
i++;
}

rs.close();
stmt.close() ;
System.out.println(\n\t*--- QUERY test is done successful
---*\n);

}
catch (SQLException e ) {
System.out.println(e);
}
}

}
___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users


Re: [U2] JDBC - ClassPath - Victory

2010-03-23 Thread Ben Souther
Glad it's working.

Tip:  You should always put the con.close() statement in a finally block.
The close method itself can throw an exception so it needs to be in a nested 
try/catch.

Putting in in a finally block insures that come Hello or high water the 
connection gets closed.
One of the most common causes for memory leaks in JDBC applications is the 
build up of unclosed database connections.


Connection con = null;
try{
// establish connection and do stuff
}catch(Exception e){
// deal with any problems
}finally{
try{
con.close();
}catch(Exception ignored){}
}







On Mar 23, 2010, at 3:33 PM, Brutzman, Bill wrote:

 The following code works ok...
 
 Thanks to all those who responded especially John, Jeff, Bruce, Charles,
 Ben, and Mike.
 
 --Bill
 
 import java.sql.*;
 
 public class Uni_101 {
 
public static void main(String[] args) {
try {
 
try {
   Class.forName(com.ibm.u2.jdbc.UniJDBCDriver); 
}
catch(Exception x){
   System.out.println( Here  + x );
} 
  String url
 = jdbc:ibm-u2://192.168.0.102/SHIPPING;
  String  userid
 = ups;
  String
 passWord  = brown;
 
Connection con = DriverManager.getConnection(url, userid,
 passWord);
 
Statement stmt = con.createStatement();
 
  String sql = select @ID, NAME,
 CITY, STATE from PACKSLIPS.X;
ResultSet rs = stmt.executeQuery(sql);
 
int i = 1;
while (rs.next()  i  6)
{
System.out.println(\nRecord + i + :);
System.out.println(\...@id : \t + rs.getString(1));
System.out.println(\tNAME :\t + rs.getString(2));
System.out.println(\tCITY :\t + rs.getString(3));
System.out.println(\tSTATE :\t + rs.getString(4));
i++;
}
 
rs.close();
stmt.close() ;
System.out.println(\n\t*--- QUERY test is done successful
 ---*\n);
 
}
catch (SQLException e ) {
System.out.println(e);
}
}
 
 }
 ___
 U2-Users mailing list
 U2-Users@listserver.u2ug.org
 http://listserver.u2ug.org/mailman/listinfo/u2-users
 

___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users