ResultSetMetaData getColumnType returning incorrect result

"Robert S Ryan" <[email protected]>
Newsgroups gmane.comp.db.mysql.bugs
Message-ID <001601c35ec1$7f7c2f90$6b01a8c0@MOBILE1>
Hi:


I'm running MySQL V 3.08 on a Win 2000 platform against a 1.3.1 Java
application which is using V 3.08 of the Connector/J JDBC driver.

I'm getting a wrong java.SQL.Type ( CHAR instead of VARCHAR ) returned
from the Connector/J  ResultSetMetaData class / getColumnType method.
The independent variable in my test is the use of the SQL keyword
Distinct. Without distinct, getColumnType correctly returns
java.SQL.VARCHAR; when I use distinct, getColumnType returns
java.SQL.CHAR. Note, this only occurs when I do a table join; I do not
see this behavior on a single table selects.  

I've appended both a test java application and schema definition.

Thanks 

Rob Ryan

-----------------------------------------------
Test source: 
-----------------------------------------------

import java.sql.*;  

public class Mysqltest {

    public static void main(String[] args) {
        Mysqltest my = new Mysqltest();
        my.go();
    }
    public void go() {
        
    try {
        Connection conn = null;
        ResultSet rs = null;
        ResultSetMetaData rsmd = null; 
        Statement stmt = null;
        String dbUrl = "jdbc:mysql://localhost/error?user=root";
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        conn = DriverManager.getConnection(dbUrl);
        stmt = conn.createStatement();    

        String s1 = "select          T1.name from T1, T2 where
T1.joiner = T2.joiner";
        String s2 = "select distinct T1.name from T1, T2 where
T1.joiner = T2.joiner";
        
        rs    = stmt.executeQuery(s1);
        rsmd  = rs.getMetaData(); 
        System.out.println(" w/o  distinct keyword : SQL Type for
T1.name = " + rsmd.getColumnType(1)); 
        rs.close();
        rs = stmt.executeQuery(s2);
        rsmd = rs.getMetaData(); 
        System.out.println(" with distinct keyword : SQL Type for
T1.name = " + rsmd.getColumnType(1)); 
        rs.close();
        conn.close();
        return;
     }
     catch (Exception e) {
        return; 
     }       
    }

}

-----------------------------------------------
Test schema for database "error"
-----------------------------------------------

create table T1 (
   name varchar(255) not null,
   joiner char(1) not null
   );

create table T2 (
   name varchar(255) not null,
   joiner char(1) not null
   );

alter table T1 
   add constraint aa primary key (name);

alter table T2 
   add constraint bb primary key (name);
   
insert into T1 (name , joiner ) values ( 'ROWT11' , '1' );  
insert into T1 (name , joiner ) values ( 'ROWT12' , '2' );  
insert into T2 (name , joiner ) values ( 'ROWT21' , '1' );  
insert into T2 (name , joiner ) values ( 'ROWT22' , '2' );  






-- 
MySQL Bugs Mailing List
For list archives: http://lists.mysql.com/bugs
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.