Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-524

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

Details

    • Bug
    • Status: Closed (View Workflow)
    • Blocker
    • Resolution: Cannot Reproduce
    • 1.5.9
    • N/A
    • JDBC 4.2 compatibility
    • None
    • 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.

      Attachments

        Activity

          diego dupin Diego Dupin added a comment - - edited

          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

          diego dupin Diego Dupin added a comment - - edited 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
          diego dupin Diego Dupin added a comment -

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

          diego dupin Diego Dupin added a comment - closing since having no answer. Feel free to re-open it if issue still occur

          People

            diego dupin Diego Dupin
            banesh banesh banna
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.