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
Hi. I bet this is due to a bug in later Oracle drivers. Try this
added property to add to your connections:
props.put("oracle.jdbc.V8Compatible", "true");
Let me know if this clears the problem up...
Joe Weinstein at BEA Systems
Thank u sir! :)
This worked like magic.I am all praise for u.
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();
}
}
itref...@gmail.com skrev: