This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Can you point me to a working sample project that uses a Derby... erm... javaDB database and successfully creates and uses a connection using the new Java EE 5 @Resource annotation (i.e., resource injection). I have a simple JSP-based project that uses JNDI lookup, and I want to simplify my code using resource injection. Specifically I here is the old JNDI code I have working ///////////// // Retrieve the DataSource from JNDI Context ctx = new InitialContext(); if ( ctx == null ) { throw new RuntimeException("JNDI Context could not be found."); } ds = (DataSource)ctx.lookup("java:comp/env/jdbc/leagueDB"); if ( ds == null ) { throw new RuntimeException("DataSource could not be found."); } // Get a database connection connection = ds.getConnection(); //////// replace the above with something like this: //////// private @Resource(name="jdbc/leagueDB") DataSource ds; ... ... // Get a database connection connection = ds.getConnection(); //////// But the call to getConnection() fails. Please point me to a working sample project, or some COMPLETE instructions.
Another way to pose the question might be: Given a working database configuration, how does one figure out the syntax for an @Resource statement? ------- Given the following database properties: Database URL: jdbc:derby://localhost:1527/league Driver: org.apache.derby.jdbc.ClientDriver and that this database connection is fully accessible from the NetBeans IDE under the runtime tab. and it works with my old JNDI lookup code. How do I form a correct @Resource statement?
1. Create a web project on Sun Java System Application Server, use Java EE 5 as the Java EE version. 2. Create a servlet. 3. Right-click inside the servlet class, invoke Enterprise Resources - Use Database. Choose the jdbc/sample data source. This generates a @Resource(name = "jdbc/sample") private DataSource jdbcSample; field. 4. You can now call jdbcSample.getConnection() somewhere in the processRequest() method. Note that dependency injection using annotations only works in managed classes (e.g., servlets, JSF managed beans, EJB's). Next time please ask questions on the nbusers@netbeans.org mailing list: http://www.netbeans.org/community/index.html Only file issues if the IDE is not working as expected, throws exceptions, etc. Thanks.