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);
}
}
}