Datasource with JBuilder

M

Mike

I have Tomcat running on my desktop for development. It has a
datasource defined in web.xml for MySQL running on another
box. Some jsps access methods in java classes residing in
WEB-INF/classes. Everything works fine if an application is run
through Tomcat.

The classes originate on JBuilder also on my desktop. The output of
JBuilder is to the webapp classes directory.

The problem is I want to run a class directly on JBuilder for
debugging purposes using the same datasource as defined in Tomcat.
When I do so I get the following error:

"javax.naming.NoInitialContextException: Need to specify class name in
environment or system property, or as an applet
parameter, or in an application resource file:
java.naming.factory.initial"

How do I configure JBuilder so it finds the datasource?


Thanks
 
M

Mike

On Fri, 26 Oct 2007 16:52:26 GMT, (e-mail address removed) (Mike) wrote:

Here's what I have. When a jsp calls "getStatement()" a valid
statement is returned and I can do a query. When I run the class from
JBuiler it can't find the datasource.


===========================================


package com_myPackage;


import java.sql.*;
import javax.sql.*;
import javax.naming.InitialContext;
import javax.naming.Context;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2004</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class DbConnector {
public DbConnector() {
}

InitialContext initCtx = null;
Connection conn = null;
Statement stmt = null;

public static void main(String[] args) {
DbConnector dbconnector = new DbConnector();
Statement stmtt = dbconnector.getStatement();

}

public Statement getStatement() {

try {
initCtx = new InitialContext();
DataSource ds = (DataSource)
initCtx.lookup("java:comp/env/jdbc/foo");

conn = ds.getConnection();
stmt = conn.createStatement();

}catch (Exception E){
E.printStackTrace();
}

return stmt;

}

public void closeItems() {

try {
conn.close();
initCtx.close();
}catch (Exception E) {

}

}

}
 
M

Mike

After doing some research I realize that the process needs JNDI which
Tomcat provides.

The question is then, how to develop and debug classes (that need
JNDI) using JBuilder. Do I need a different development platform?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top