Java.sql.SQLException: Cannot convert to internal representation Exception

Please find my request below.

select nvl(max(transaction_id),0) as  transaction_id from exception_details;

If I fulfilled the above request through my jdbc code, it gives me java.sql.SQLException: Fail to convert to internal representation my JDBC code as follows:

public int fetchColumnVal(String query) throws SQLException, IllegalAccessException, 
    InvocationTargetException, NoSuchMethodException, ClassNotFoundException, InstantiationException {

    PreparedStatement pstmt = null;
    Connection con = null;
    try {
        con = getConnection(true);
        pstmt = con.prepareStatement(query);
        ResultSet rs = pstmt.executeQuery();
        rs.next();
        int count=rs.getInt(1);
        return count;
    } finally {
        if (isBatchMode) {
            this.cleanResources(null, pstmt);
        }
        else {
            this.cleanResources(con, pstmt);
        }
    }
}

and the data type for the transaction_id column in the table is NUMBER

+4
source share
4 answers

SQL JDBC / Java setXXX getXXX

NUMERIC java.math.BigDecimal setBigDecimal getBigDecimal

change rs.getInt (1); to rs.getBigDecimal (1);

(or) enter the number of litas into an integer in sql, as shown below for the oracle:

CAST (id AS integer)

0
source

ResultSet. :

       while (RS.next()) {
            RScount = RS.getInt(1);
            Set.add(RS.getString(1));
        }

SQL- String, Java :

java.sql.SQLException: Fail to convert to internal representation

Vanilla: , 0:

Integer RScount = 0; //SQL result set counter

:

    while (RS.next()) {
        RScount++;
        Set.add(RS.getString(1));
    }
0

,

Foundjava.sql.SQLException: .

:

 while(res.next())  
        System.out.println(  res.getInt(1) + "  "
                           + res.getString(2) + "  "
                           + res.getString(3) + "  "
                           + res.getString(4));

1- varchar.

:

while(res.next())  
        System.out.println(  res.getString(1) + "  "
                           + res.getString(2) + "  "
                           + res.getString(3) + "  "
                           + res.getString(4));

.

0

@Enumerated EnumType.STRING, i.e @Enumerated (EnumType.STRING) String (Varchar), , cos. default EnumType ORDINAL, EnumType.ORDINAL.

0

All Articles