Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8198397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:56:33+00:00 2026-06-07T05:56:33+00:00

Warning: New to Java I have a simple Netbeans project – I wanted to

  • 0

Warning: New to Java

I have a simple Netbeans project – I wanted to just learn about interacting with DB’s coming from php I thought I would have a go with a local one running on my computer.

Lots of the examples out there say to use the InitialContext() object to refer to the database resource.

After following the examples I get the following exception – Lots of Google stuff points to some .xml file – which I have no idea about or even where it exists in the Netbeans project? I’m not using a Webserver at this time so not Tomcat or anything like that, just local Java program to do this, I suspect this might be the problem. Could anyone shed some light on this?

Exception thrown 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.


package learningjava;
import com.mysql.jdbc.jdbc2.optional.*;
import com.mysql.jdbc.Driver;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.*;



public class LearningJava {

    public static void main(String[] args) {

       MysqlDataSource test_db = new MysqlDataSource(); 

       test_db.setServerName("localhost");
       test_db.setDatabaseName("dev");

       try {

            InitialContext test_db_context = new InitialContext();
            test_db_context.bind("jcdb/testdb", test_db);
            MysqlDataSource test_db_datasource = (MysqlDataSource)test_db_context.lookup("testdb");

       } catch (NamingException e) {

           System.out.println("Exception thrown " + e);

       }
        try {

            test_db.getConnection("root","password");

        } catch (SQLException e) {

             System.out.println("Exception thrown " + e);

        }


    }    

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:56:33+00:00Added an answer on June 7, 2026 at 5:56 am

    In general you should understand that JNDI should have a server. In a code snippet you’ve provided you’re using a _CLIENT_SIDE_ part of JNDI technology when you’re doing your lookup. There should be a JNDI server that should be accessible from your local client connection.
    Once configured properly, the call to lookup should issue a connection with JNDI server and provide a way to obtain/bind resources to that server.

    How to configure JNDI properly?

    Usually you should supply a properties file that will contain a host name of this server, a port + some implementation specific information.

    JNDI server is usually already provided when you’re using application server (like JBoss or Web Sphere).
    I think this is the root of misunderstanding here.

    Hope, this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Java and have a question about a warning: My general code:
Just a warning: I'm completely new to Java and am trying to teach myself
While creating new Java project in Eclipse I got following warning The current workspace
Warning : I have just picked up Maven, so things mentioned might be wrong
I have an old personal project written in Java 1.4 that I am porting
I recently migrated an older application we have at work from Java 1.5 to
I have a GUI written using netbeans with a few simple components in place.
I cant get rid of one new typesafety warning in java7. I have the
I have this java code: try { PDFTextStripper pdfs = new PDFTextStripper(); String textOfPDF
I'm a Java newbie, and also new to OOP. I have been a procedural

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.