2

Disclaimer: I don't actually know anything about nether Oracle nor Java. The issue is in a project that some other developer completed at some point in time and then left the company. Now I have to setup webserver, database and get it all up and running.

the code is approx this:

OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:<user>/<password>@localhost:1521:xe");
OracleConnection ocon = (OracleConnection)ods.getConnection();
OracleStatement stmt = (OracleStatement)ocon.createStatement();
OracleResultSet rs = (OracleResultSet)stmt.executeQuery("SELECT POLLID, QUESTION, ISMULTISELECT FROM POLL WHERE POLLID = " + pollID);

if (!rs.next()) {
    System.out.println("No rows found.");
    return false;
}
this._PollID = rs.getInt("POLLID");
this._Question = rs.getString("QUESTION");
this._IsMultiSelect = rs.getBoolean("ISMULTISELECT");

The POLLID and ISMULTISELECT columns return correct values as expected. The QUESTION seem to always return empty string. The value in the DB is obviously not empty.

The rs.getAsciiStream("QUESTION").available() also returns zero.

Am I missing something completely obvious here?

EDIT:

  • sqlplus returns varchar2 value just fine

  • connecting via odbc (as opposed to thin) also makes things work

12
  • What happens when you run the query by itself in SQL Plus or SQL Developer? (SQL Developer is free and a snap to set up, esp. since the user/psrd & server are already present for you)
    – Harrison
    Nov 15, 2010 at 18:03
  • sqlplus returns data just fine.
    – Ilia G
    Nov 15, 2010 at 20:26
  • 1
    What datatype is QUESTION in the table - VARCHAR2? CLOB?
    – Alex Poole
    Nov 15, 2010 at 21:48
  • 1
    Does rs.getString(2) (with the column index instead of the column name) return the correct value? Nov 18, 2010 at 9:56
  • 2
    Just a side comment...you should never use string concatenation like that to build a query. That allows SQL injection hacking.
    – JOTN
    Nov 19, 2010 at 4:03

6 Answers 6

1

so no Exceptions, you are not using reserved words...maybe try to use other driver, or select into other table and experiment start with empty QUESTION column, then add some value and debug.

1
  • is there a specific java/driver/oracle version combination i should be aiming for?
    – Ilia G
    Nov 12, 2010 at 20:51
1

Thanks to everyone who replied. At this point it seems issue is between thin driver and XE version of Oracle. Unfortunately we don't have full version kickin' around (we are primarily ASP.NET/MS SQL developers), so we'll have to stick with ODBC driver for now and hope issue will magically resolve itself when we push it to live environment (hosted by third party). Very crappy assumption to make, but at this point I see no other options....

1

I had the same exact issue and found that the root of the problem comes from the orai18n.jar. once i removed this from my classpath, the issue went away.

1

I have the same problem. I do not have access to the driver that is used because the connection is taken from a Weblogic server using JNDI. I cannot remove any .jar from the server neither.

The workaround I found :

String value = new String(resultset.getBytes());

Make sure you use the right encoding if required :

String value = new String(resultset.getBytes(), [CHARSET])
0

I had this same issue with eclise GCJ ( Stock centos6 ) and mysql-connector with the same concatenated queries. The problem was solved with reverting back to openJDK.

0

I had the same issue. "getInt()" would return correct value from Oracle 9i DB, but using "getString()" would result into empty string, no matter how many times i ran, within eclipse or outside on seperate Tomcat or other servers.

After going through a lot of various threads, and quite a few trials, I came to the conclusion that the issue is with the version of ojdbc6.jar that I was using. Earlier, I was using ojdbc6.jar with Oracle version 12.1.0.1., which is not so good for connecting to OLD Oracle 9i DB. After realising, I switched on to ojdbc6.jar from Oracle 11.2.0.3 and it worked like a charm.

Hope it helps. cheers!

2
  • It should have been a comment. Dec 14, 2017 at 14:42
  • yeah i dont have enough points to comment on others post yet!
    – Calvin
    Dec 15, 2017 at 16:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.