kimminsung / log4jdbc-remix

Automatically exported from code.google.com/p/log4jdbc-remix
0 stars 0 forks source link

java.lang.RuntimeException: ResultSet.getXXX(colName): could not look up name #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a simple select to multiples tables with JOIN and columns alias. 
Example: SELECT p.id, p.name, d.name AS department FROM person p LEFT JOIN 
department d USING (id_department)
2. When try to retrieve rs.getString("department") the program thorw error.

What is the expected output? What do you see instead?
I expect retrieve the coulmn data, but throw error

What version of the product are you using?
My used versio is: log4jdbc-remix 0.2.4

Iam using spring, when remove the jdbc-remix datasource Spied the program work, 
but the error is present with jdbc-remix datasource.
Iam using mysql 5.0.51a-24+lenny5 and mysql-connector-java 5.1.15 on windows xp.

Detail of error stack here:

java.lang.RuntimeException: ResultSet.getXXX(colName): could not look up name
    at net.sf.log4jdbc.DefaultResultSetCollector.setColIndexFromGetXXXMethodParams(DefaultResultSetCollector.java:163)
    at net.sf.log4jdbc.DefaultResultSetCollector.methodReturned(DefaultResultSetCollector.java:107)
    at net.sf.log4jdbc.ResultSetSpy.reportAllReturns(ResultSetSpy.java:89)
    at net.sf.log4jdbc.ResultSetSpy.reportReturn(ResultSetSpy.java:261)
    at net.sf.log4jdbc.ResultSetSpy.getString(ResultSetSpy.java:2553)
    at ve.com.pdvsa.intevep.edgeview.dao.imp.LevantamientoDAOImp$LevantamientoMapper.mapRow(LevantamientoDAOImp.java:256)
    at ve.com.pdvsa.intevep.edgeview.dao.imp.LevantamientoDAOImp$LevantamientoMapper.mapRow(LevantamientoDAOImp.java:1)
    at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:92)
    at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:1)
    at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:648)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:586)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:673)
    at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:728)
.............
........

Original issue reported on code.google.com by castocol...@gmail.com on 4 Apr 2011 at 6:49

GoogleCodeExporter commented 9 years ago
I was able to avoid the error by adjusting the log level. I am not sure which 
one of these disabled the logging that was causing the problem (logback 
configuration):

<logger name="jdbc.sqlonly" level="OFF"/>
<logger name="jdbc.sqltiming" level="OFF"/>
<logger name="jdbc.audit" level="OFF"/>
<logger name="jdbc.resultset" level="OFF"/>
<logger name="jdbc.resultsettable" level="OFF"/>
<logger name="jdbc.connection" level="OFF"/>

Original comment by j...@jarretttaylor.com on 6 Oct 2011 at 8:05

GoogleCodeExporter commented 9 years ago
Disabling the result set logging seems a bit drastic, since it is one of the 
best features of this project. I have found another solution. The 
colNameToColIndex field of DefaultResultSetCollector seems to contain only the 
names of the columns, but the getXXX methods can also ask for column labels. 
When replacing the following code:

  private void setupColNameToColIndexMap() {
    int columnCount = getColumnCount();
    colNameToColIndex = new HashMap<String, Integer>(columnCount);
    for (int column = 1; column <= columnCount; column++) {
      colNameToColIndex.put(getColumnName(column).toLowerCase(), column);
    }
  }

with a more general

  private void setupColNameToColIndexMap() {
    int columnCount = getColumnCount();
    colNameToColIndex = new HashMap<String, Integer>(columnCount);
    for (int column = 1; column <= columnCount; column++) {
      colNameToColIndex.put(getColumnName(column).toLowerCase(), column);
      colNameToColIndex.put(getColumnLabel(column).toLowerCase(), column);
    }
  }

  public String getColumnLabel(int column) {
      try {
        return metaData.getColumnLabel(column);
      } catch (SQLException e) {
        throw new RuntimeException(e);
      }
    }

it works as expected.
Can anyone include this in the source and publish it to the maven repositories?

Original comment by betermi...@gmail.com on 31 Oct 2011 at 12:10

GoogleCodeExporter commented 9 years ago
I've added the fix from comment 2 and checked in to svn with some test code. 
However its not in the maven repositroy yet

Original comment by tim.azzo...@gmail.com on 7 Nov 2011 at 4:14

GoogleCodeExporter commented 9 years ago

Original comment by tim.azzo...@gmail.com on 7 Nov 2011 at 4:18

GoogleCodeExporter commented 9 years ago
hopefully this is fixed now ! in version 0.2.5

Original comment by tim.azzo...@gmail.com on 7 Nov 2011 at 10:52