1

I have a simple SQL code that returns one record but when I execute it from Java, it does not return the string portions of the record, only numerical. The fields are VARCHAR2 but do not get extracted into my resultset. Following is the code. The database connectivity portion has been edited out for posting in the forum but it does connect. I have also attached the output. Any guidance would be appreciated as my searches on the web have returned empty. -Greg

package testsql;

import java.sql.*;

public class TestSQL {

    String SQLtracknbr;
    int SQLtracklength;
    int numberOfColumns;
    String coltypename;
    int coldispsize;
    String SQLschemaname;

  public static void main(String[] args)
      throws ClassNotFoundException, SQLException
  {
    Class.forName("oracle.jdbc.driver.OracleDriver");

    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());

        String url = "jdbc:oracle:thin:@oracam.corp.mot.com:1522:oracam";

        String SQLcode = "select DISTINCT tracking_number from sfc_unit_process_track where tracking_number = 'CAH15F6WW9'";

        System.out.println(SQLcode);

        Connection conn =
         DriverManager.getConnection(url,"report","report");

    conn.setAutoCommit(false);
      try (Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery(SQLcode)) {

          ResultSetMetaData rsmd = rset.getMetaData(); 

          while (rset.next()) {

        int numberOfColumns = rsmd.getColumnCount();
        boolean b = rsmd.isSearchable(1);
        String coltypename = rsmd.getColumnTypeName(1);
        int coldispsize = rsmd.getColumnDisplaySize(1);
        String SQLschemaname = rsmd.getSchemaName(1);

        String SQLtracknbr = rset.getString(1);
        int SQLtracklength = SQLtracknbr.length();

        if (SQLtracknbr == null)
              System.out.println("NULL**********************.");
        else
           System.out.println("NOT NULL.");

        System.out.println("numberOfColumns = " + numberOfColumns);
        System.out.println("column type = " + coltypename);
        System.out.println("column display size = " + coldispsize);
        System.out.println("tracking_number = " + SQLtracknbr);
        System.out.println("track number length = " + SQLtracklength);
        System.out.println("schema name = " + SQLschemaname);
          }
      }
    System.out.println ("*******End of code*******"); 
}
}

The result of what is executed in Java is below:

run:

select DISTINCT tracking_number from sfc_unit_process_track where tracking_number = 'CAH15F6WW9'

NOT NULL.
numberOfColumns = 1
column type = VARCHAR2
column display size = 30
tracking_number =
track number length = 0
schema name =
*******End of code*******
BUILD SUCCESSFUL (total time: 0 seconds)
6
  • At a guess, maybe when you use 1 in that while loop, you're supposed to be using 0? Commented Jan 15, 2015 at 17:44
  • What happens if you run that query in SQL*Plus as the same user you're connecting with from Java? Do you have any virtual private database policies in place, maybe? What database and driver versions are you using, just in case you have a known problematic combination. Commented Jan 15, 2015 at 17:57
  • @DaaaahWhoosh - the 1 is referencing the correct column. Numbering starts at 1 and not zero. I have another query, a modification of this one, that pulls more columns and the same issue...no strings returned. Commented Jan 15, 2015 at 20:41
  • @AlexPoole- Server is Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production. I have ojdbc7.jar loaded on my machine. If I run my query using PL/SQL, I get the correct result (well data returned by the SQL that is). Commented Jan 15, 2015 at 20:46
  • Then it may be a compatibility issue; ojdbc7 only seems to be supported for 12c. Can you try it with a different driver version to verify if it works? Commented Jan 16, 2015 at 12:13

1 Answer 1

1

This seems to be caused by an incompatibility between the driver you're using, ojdbc7.jar, and the version of the database you're connecting to, 9i.

According to the JDBC FAQ section "What are the various supported Oracle database version vs JDBC compliant versions vs JDK version supported?", the JDK 7/8 driver ojdbc7.jar that you're using is only support for Oracle 12c.

Oracle generally only support client/server versions two release apart (see My Oracle Support note 207303.1), and the Oracle 12c and 9i client and server have never been supported either way around. JDBC is slightly different of course, but it may be related, as drivers are installed with the Oracle software.

You will have to upgrade your database to a supported version, or - perhaps more practically in the short term - use an earlier driver. The Wayback Machine snapshot of the JDBC FAQ from 2013 says the 11.2.0 JDBC drivers - which includes ojdbc6.jar and ojcbd5.jar - can talk to RDBMS 9.2.0. So either of those ought to work...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.