[CONJ-524] java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String Created: 2017-09-12  Updated: 2017-11-20  Resolved: 2017-11-20

Status: Closed
Project: MariaDB Connector/J
Component/s: JDBC 4.2 compatibility
Affects Version/s: 1.5.9
Fix Version/s: N/A

Type: Bug Priority: Blocker
Reporter: banesh banna Assignee: Diego Dupin
Resolution: Cannot Reproduce Votes: 0
Labels: None
Environment:

java 1.7 with 1.5.9 version.



 Description   

public <T> T getObject(String columnLabel, Class<T> type) throws SQLException;

integer column reading as string .But iam passing class as second parameter to getObject Method.

In mysql the value returning as String .
But in Maria DB driver it is giving as Integer.



 Comments   
Comment by Diego Dupin [ 2017-09-12 ]

Hi banesh
I'm not sure to understand issue well : column type is integer, and you use Resultset.getObject(int columnIndex, Class<T> type), with parameter String.class ?

I've test this with mysql/mariadb connector with different version without any issue :

        try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/testj?user=root")) {
            try (Statement stmt = connection.createStatement()) {
                try (ResultSet rs = stmt.executeQuery("SELECT 1")) {
                    rs.next();
 
                    Object obj = rs.getObject(1, Integer.class);
                    System.out.println(obj.getClass().getCanonicalName() + " " + obj);
 
                    obj = rs.getObject(1, String.class);
                    System.out.println(obj.getClass().getCanonicalName() + " " + obj);
                }
            }
        }

resulting in :
java.lang.Integer 1
java.lang.String 1

Comment by Diego Dupin [ 2017-11-20 ]

closing since having no answer.
Feel free to re-open it if issue still occur

Generated at Thu Feb 08 03:16:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.