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
joeNOSPAM@BEA.com - 13 Nov 2006 20:06 GMT
On Nov 13, 11:58 am, itrefle...@gmail.com wrote:
> Hello,
> If anyone has faced this problem or can guide me in right direction
[quoted text clipped - 41 lines]
> 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
itreflects@gmail.com - 13 Nov 2006 20:42 GMT
> Hi. I bet this is due to a bug in later Oracle drivers. Try this
> added property to add to your connections:
[quoted text clipped - 3 lines]
> 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.
bjorn.ahl@gmail.com - 04 Dec 2006 21:46 GMT
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@gmail.com skrev:
> Hello,
> If anyone has faced this problem or can guide me in right direction
[quoted text clipped - 42 lines]
> org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)
> ... and so on
itreflects@gmail.com - 18 Dec 2006 01:52 GMT
Thanx for sharing code. Yeah, i think oracle guys fixed that bug in new
driver version. However there is an alernate solution to the problem if
u r still using 9.2* version of drivers i.e oracle does its own
implementation CachedRowSet (look for OracleCachedRowSet in oro*.jar
file shipped with installation, sorry can't remember exact jar file
name) and that takes care of TimeStamp related issue.I was using Sun
implementation of CachedRowSet with Oracle db, hence faced that
exception.
> I Tested that with oracle Jdbc version 10.2.0.1 and gott it to work. :D
>
[quoted text clipped - 52 lines]
> }
> }