Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Datasource with JBuilder

Thread view: 
Mike - 26 Oct 2007 17:52 GMT
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
Mike - 26 Oct 2007 18:42 GMT
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) {

       }

   }

}
Mike - 26 Oct 2007 19:53 GMT
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?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.