Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4041727

The close (from DriverManager.getConnection(url,usr,pwd)) prevents printing more

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.1
    • core-libs
    • None
    • x86
    • windows_95



      Name: sgC58550 Date: 03/27/97


      The close (from DriverManager.getConnection(url,usr,pwd)) messes up the System.out.println
      outside the method by preventing display of more than 2 lines.

      // File named "contst.java"
      // The problem line is "con.close" but it might have something
      // to do with other stuff, such as "stmt.close();"

      import java.net.URL;
      import java.sql.*;
      import sun.jdbc.odbc.JdbcOdbcDriver;

      class contst {
          String[] tstarr = new String[100];

          private static String url = "jdbc:odbc:poll";

          public String[] justconnect () {
              try {
                  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                  Connection con = DriverManager.getConnection(url, "", "");
                  Statement stmt = con.createStatement();

                  for(int i=0; i<10; i++) { tstarr[i] = "component#" + i; }

                  stmt.close();
                  con.close(); // <-- This is the problem line
              }The
      catch( Exception e) {
      System.out.println( e.getMessage());
      e.printStackTrace();
      }
      return tstarr;
      }
      }
      ----------------------------------------------------------------

      //File named "contstmain.java"

      import contst;

      class contstmain {

      //***********************************************************************
      // the MAIN part
      //
          public static void main(String argv[]) {
              contst X = new contst();
              try {
                  String[] tstarr = new String[100];
                  tstarr = X.justconnect();
                  for(int i=0; i<10; i++) { System.out.println(tstarr[i]); }
                  // The line above is where it prints only 2 lines at most
              }
      catch( Exception e) {
      System.out.println( e.getMessage());
      e.printStackTrace();
      }
          }
      }
      ----------------------------------------------------------------

      company - Espectra Media, Inc. , email - ###@###.###
      ======================================================================

            mhapnersunw Mark Hapner (Inactive)
            sgoodsunw Sheri Good (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: