[jboss-user] [JBoss Tools Users] - Re: How to create a JDBC connection

Oliver Roell do-not-reply at jboss.com
Thu Sep 3 06:02:17 EDT 2009


I know that JPA is the future of Java's database-access, but I want to use JDBC in my servlet.
There is an existing oracle-database from our SAP-system and I want to read customer-information with a select.

The "JMX Agent View" from JBoss displays under "jboss.jdbc":

datasource=DefaultDS,service=metadata
datasource=OracleDS,service=metadata

I think the deploying of the oracle-datasource was successful.

The book "EJB 3 in action" wrotes on page 148:
Moreover, application servers allow you to explicitly specify a global JNDI name using the mappedName parameter of the @Resource annotation. For example, if you are using the JBoss Application Server and you have a data source with a global JNDI name of java:/DefaultDS, you can specify the resource mapping as follows:


  | @Resource(name="jdbc/ActionBazaarDS", mappedName="java:/DefaultDS")
  | private javax.jdbc.DataSource myDB;
  | 

I do not know why the DataSource from "EJB 3 in action" belongs to the package javax.jdbc
I am working with the DataSource from the package javax.sql

In my servlet I have tried the following:


  | @Resource(name="jdbc/OracleDS", mappedName="java:/OracleDS")
  | private javax.sql.DataSource ds;
  | ...
  | Connection con = ds.getConnection();
  | Statement statement = con.createStatement();
  | ResultSet resultSet = statement.executeQuery("select...");
  | 

The ds object is always null. JBoss does not recognize the @Resource-annotation.

Do I miss something?

Do I still need a jbosscm-jdbc deployment descriptor in JBoss 4.2.3 when I work with annotations?



View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4253273#4253273

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4253273



More information about the jboss-user mailing list