cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with JDBC - Cannot convert SQL type CHAR BYTE to Java type

Former Member
0 Kudos

Hello all,

Does anybody know something about this JDBC problem?

I have a problem with JDBC driver. I using version 7.06.05.

Example of my code

Statement st = conn.createStatement();

ResultSet rs = st.executeQuery("SELECT null as LONG_COL FROM DUAL");

rs.next();

addResultItem("LONG_COL", String.valueOf(rs.getLong(1)));

The exception is:

com.sap.dbtech.jdbc.translators.ConversionExceptionSapDB: Cannot convert SQL type CHAR BYTE to Java type long.

at com.sap.dbtech.jdbc.translators.DBTechTranslator.newGetException(DBTechTranslator.java:1195)

at com.sap.dbtech.jdbc.translators.DBTechTranslator.getLong(DBTechTranslator.java:596)

at com.sap.dbtech.jdbc.ResultSetSapDB.getLong(ResultSetSapDB.java:1121)

at com.sap.dbtech.jdbc.trace.ResultSet.getLong(ResultSet.java:180)

But when I run this sql code inside MaxDB Studion - Everything is ok,

Please help me

Thanks all

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

beside the fact that I do not catch, what you really want to do or to test:

SELECT fixed(NULL) from dual (no matter if the output-column is renamed or not)

returns the NULL-value, when the result ist fetched/the next resultrow got.

Of course, the select itself, returns the fact, that there is no error with the returncode 0.

We do not see, where you catch the 0 from and therefore we assume that you mix something up during this select.

Elke

Former Member
0 Kudos

I tried now this

... = st.executeQuery("SELECT FIXED(null) as LONG_COL FROM DUAL");

and this works. But return value 0 instead of NULL.

Is this correct solution?

lbreddemann
Active Contributor
0 Kudos

>Example of my code

>

> Statement st = conn.createStatement();

> ResultSet rs = st.executeQuery("SELECT null as LONG_COL FROM DUAL");

> rs.next();

> addResultItem("LONG_COL", String.valueOf(rs.getLong(1)));

>

> The exception is:

> com.sap.dbtech.jdbc.translators.ConversionExceptionSapDB: Cannot convert SQL type CHAR BYTE to Java type long.

> at com.sap.dbtech.jdbc.translators.DBTechTranslator.newGetException(DBTechTranslator.java:1195)

> at com.sap.dbtech.jdbc.translators.DBTechTranslator.getLong(DBTechTranslator.java:596)

> at com.sap.dbtech.jdbc.ResultSetSapDB.getLong(ResultSetSapDB.java:1121)

> at com.sap.dbtech.jdbc.trace.ResultSet.getLong(ResultSet.java:180)

>

Why do you think that you get a LONG datatype back, when you rename the column as "LONG_COL" ?

You select NULL and don't cast any datatype. In that case you get a CHAR back instead of a LONG.

In MaxDB Database Studio the resultset is first examined for its datatypes and fetched afterwards.

BTW: why do you want to select NULL into a LONG datatype?

regards,

Lars