• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Gautam Ry
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic