Re: CachedRowSetImpl.getTimestamp() throwing exception



I Tested that with oracle Jdbc version 10.2.0.1 and gott it to work. :D

My Test code
import java.sql.Timestamp;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.sun.rowset.CachedRowSetImpl;
import java.sql.Date;


public class CachedRowSetImplTest {

public static void main(String args []) {
CachedRowSetImplTest runMe = new CachedRowSetImplTest();
}
/** Creates a new instance of CachedRowSetImplTest */
public CachedRowSetImplTest() {

Connection conn;
try {

DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
} catch (SQLException ex) {
ex.printStackTrace();
}
try {
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ora10gr2",
"scott", "tiger");
} catch( Exception e ) {
System.out.println( "error connecting" );
e.printStackTrace( );
return;
}
try {
// Create a Statement
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select ename, hiredate
from emp");
CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(rset);
System.out.print("test");
while (crs.next()) {
//java.sql.TimeStamp =
Timestamp myTimeStamp = crs.getTimestamp("HIREDATE");
// EOD_DATE coulmn is of type DATE, this line is throwing
System.out.println(crs.getTimestamp("HIREDATE"));

}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
itreflects@xxxxxxxxx skrev:

Hello,
If anyone has faced this problem or can guide me in right direction
please..
I am clueless abt this exception. I have a java piece of code as (note:
implementation of CachedRowSetImpl comes default with JRE1.5 in
com.sun.rowset.CachedRowSetImpl):


ResultSet rs = stmt.executeQuery(sql);

CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(rs);

while (crs.next()) {
java.sql.TimeStamp = crs.getTimestamp("EOD_DATE"); // EOD_DATE coulmn
is of type DATE, this line is throwing exception, why???
}

when result set contains a column of DATE (in Oracle 9.2.0.4 version,
inserted using SYSDATE), program is throwing this exception:

java.lang.ClassCastException: java.sql.Timestamp
at
com.sun.rowset.CachedRowSetImpl.getTimestamp(CachedRowSetImpl.java:2289)
at
com.sun.rowset.CachedRowSetImpl.getTimestamp(CachedRowSetImpl.java:2740)
at
com.itaas.action.chart.DailyTunerActivityChart.createDataset4(DailyTunerActivityChart.java:190)
at
com.itaas.action.chart.DailyTunerActivityChart.getChartObject(DailyTunerActivityChart.java:68)
at
com.itaas.action.DailyTunerAction.execute(DailyTunerAction.java:104)
at
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:53)
at
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:64)
at
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:48)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:280)
at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)
... and so on

.