wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes please, help me to solve  sun.jdbc.odbc.JdbcOdbcDriver cannot be cast to javax.sql.DataSource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "please, help me to solve  sun.jdbc.odbc.JdbcOdbcDriver cannot be cast to javax.sql.DataSource" Watch "please, help me to solve  sun.jdbc.odbc.JdbcOdbcDriver cannot be cast to javax.sql.DataSource" New topic
Author

please, help me to solve sun.jdbc.odbc.JdbcOdbcDriver cannot be cast to javax.sql.DataSource

Gautam Ry
Ranch Hand

Joined: Dec 30, 2008
Posts: 41
Hi there

I am using NetBeans6.5,SQL 2000 and GlassFish server to develop the following
@onetoOne mapping.

Entitys:

@Entity
@Table(name = "Shipments")
@NamedQueries({@NamedQuery(name = "Shipments.findAll", query = "SELECT s FROM Shipments s")})
public class Shipments implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "ShpmentId")
private String shpmentId;
@Column(name = "City")
private String city;

public Shipments() {
}

public Shipments(String shpmentId) {
this.shpmentId = shpmentId;
}

public String getShpmentId() {
return shpmentId;
}

public void setShpmentId(String shpmentId) {
this.shpmentId = shpmentId;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

}

another entity:
@Entity
@Table(name = "Orders")
@NamedQueries({@NamedQuery(name = "Orders.findAll", query = "SELECT o FROM Orders o")})
public class Orders implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "OrderId")
private String orderId;
@Column(name = "OrderName")
private String orderName;
private Shipments objShipment;



public Orders() {
}



public String getOrderId() {
return orderId;
}

public void setOrderId(String orderId) {
this.orderId = orderId;
}

public String getOrderName() {
return orderName;
}

public void setOrderName(String orderName) {
this.orderName = orderName;
}
@OneToOne(cascade={CascadeType.PERSIST})
public Shipments getObjShipment()
{
return objShipment;
}

public void setObjShipment(Shipments objShipment) {
this.objShipment = objShipment;
}

}

Session Bean:
@Stateless
public class NewSessionBean implements NewSessionLocal {
@PersistenceContext
EntityManager em;
public void doSomeStuff()
{
Shipments objs=new Shipments();
objs.setShpmentId("1001");
objs.setCity("Bangalore");

Orders ord=new Orders();
ord.setOrderId("1001");
ord.setOrderName("Software");
ord.setObjShipment(objs);
em.persist(ord);
}

}

Jsp File
<%@page import="javax.ejb.*,
javax.naming.*,java.util.*,
com.sisl.ejb.NewSessionLocal;"
%>
<%!
NewSessionLocal objHello;
public void jspInit()
{
try
{
Context ctx=new InitialContext();
objHello=(NewSessionLocal)ctx.lookup("java:comp/env/ejb/NewSessionBean");
}
catch(Exception e)
{
System.out.println("Exception thrown...............");
e.printStackTrace();

}
}

%>
<html>
<body>
Send Data
<%
objHello.doSomeStuff();
%>
</body>
</html>

Persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="EnterpriseApplication6-ejbPU" transaction-type="JTA">
<jta-data-source>dsncity</jta-data-source>
<class>com.sisl.ejb.Shipments</class>
<class>com.sisl.ejb.Orders</class>
</persistence-unit>
</persistence>

Error log in GlassFish:

javax.ejb.EJBException: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: null; nested exception is:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: sun.jdbc.odbc.JdbcOdbcDriver cannot be cast to javax.sql.DataSource


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
The JDBC/ODBC bridge driver is quite basic, and long predates the DataSource class. Anytime you find yourself wanting to use a DataSource, or are working in an enterprise application, that's a strong indication to use a better driver. (The bridge driver is also buggy and not thread-safe.) The jTDS driver handles MS SQLServer 2000 quite nicely.


Ping & DNS - updated with new look and Ping home screen widget
Gautam Ry
Ranch Hand

Joined: Dec 30, 2008
Posts: 41
But the same thing is working fine in the weblogic server. So, I can n't agree with the
point that the Driver is buggy.
Any way, could you explain the steps to configure
NetBeans with the iJTDS as You told .
What is the Driver Class name for ijTDS?

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
The bridge driver is positively buggy (and not thread-safe). It's possible that a different app server uses it in a different manner and thus doesn't expose its problems as quickly, but if you search around the net you'll find many problem reports.

Googling for "jtds" will get you to its home page, which has extensive documentation available.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please, help me to solve sun.jdbc.odbc.JdbcOdbcDriver cannot be cast to javax.sql.DataSource
 
Similar Threads
How to delete individual entity in @OneToOne without affecting each other?
Please explain this @OneToOne
jsf navigation and database connection
EJB3 Entity Bean won't verify with Netbeans
How to delete individual entity in @OneToOne without affecting each other?