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

SQL Server: getString() on text column with null value throws Exception

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • core-libs
    • beta
    • x86
    • windows_2000



      Name: boT120536 Date: 01/15/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      When retrieving a null value from an SQL database column of type 'text'
      an SQLException is thrown.
      Retrieving a null value from a varchar(20) column returns null as expected.

      Source:

      package untitled15;

      /**
       * Title:
       * Description:
       * Copyright: Copyright (c) 2001
       * Company:
       * @author
       * @version 1.0
       */
      import java.sql.*;

      public class Untitled1
      {

        public Untitled1()
        {
        }
        public static void main(String[] args)
        {
          try
            {
              String url="jdbc:odbc:saffron";
              String login = "sa"; // use your login here
              String password = ""; // use your password
      here

              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            Connection c = DriverManager.getConnection(url,login,password);

            Statement s = c.createStatement();
            s.execute("DROP TABLE testtable");
            s.execute("CREATE TABLE testtable(testColumn VARCHAR(20) )");
            s.execute("INSERT INTO testtable VALUES (NULL)");
            s.execute("SELECT * from testtable");
            ResultSet rs = s.getResultSet();
            rs.next();
            String o =(rs.getString(1));
            System.out.println(o);

            s.execute("DROP TABLE testtable");
            s.execute("CREATE TABLE testtable(testColumn text )");
            s.execute("INSERT INTO testtable VALUES (NULL)");
            s.execute("SELECT * from testtable");
            rs = s.getResultSet();
            rs.next();
            o =(rs.getString(1));
            System.out.println(o);

            }
            catch (Exception e)
            {
            System.out.println(e.getMessage());
            e.printStackTrace();
            }
          }

      }
      (Review ID: 115134)
      ======================================================================

            jellissunw Jon Ellis (Inactive)
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: