JNDI Example in Stand Alone Application..

..which returns a Data Source.

Pretty much refactoring of Scott Nelson 's answer here. Thanks Scott for the great answer!
import org.apache.commons.dbcp2.BasicDataSource;
 
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
import javax.naming.spi.InitialContextFactoryBuilder;
import javax.naming.spi.NamingManager;
 
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Hashtable;
 
class MyInitialContext extends InitialContext {
    private Hashtable<String, DataSource> dataSources = new Hashtable<>();
 
    public MyInitialContext() throws NamingException {
    }
 
    @Override
    public Object lookup(String name) throws NamingException {
        if (dataSources.isEmpty()) { //init datasources
            final BasicDataSource ds = new BasicDataSource();
            ds.setUrl("jdbc:h2:tcp://localhost:9092/~/h2dbs/studentform");
            ds.setUsername("sa");
            ds.setPassword("");
            dataSources.put("jdbc/studentform", ds);
        }
        if (dataSources.containsKey(name)) {
            return dataSources.get(name);
        }
        throw new NamingException("Unable to find datasource: " + name);
    }
}
 
class MyInitialContextFactory implements InitialContextFactory {
    @Override
    public Context getInitialContext(Hashtable<?, ?> hashtable)
            throws NamingException {
        final MyInitialContext myInitialContext;
        myInitialContext = new MyInitialContext();
        return myInitialContext;
    }
}
 
class MyInitialContextFactoryBuilder implements InitialContextFactoryBuilder {
    @Override
    public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> hashtable) {
        final MyInitialContextFactory myInitialContextFactory
                = new MyInitialContextFactory();
        return myInitialContextFactory;
    }
}
 
public class InitialContextInStandAloneExample {
 
    public static void main(String[] args) throws NamingException, SQLException {
        final InitialContextFactoryBuilder initialFactoryBuilder
                = new MyInitialContextFactoryBuilder();
        NamingManager.setInitialContextFactoryBuilder(initialFactoryBuilder);
 
        final InitialContext initialContext = new InitialContext();
        final BasicDataSource bds = 
                (BasicDataSource) initialContext.lookup("jdbc/studentform");
 
        final Connection connection = bds.getConnection();
        final Statement statement = connection.createStatement();
        final ResultSet resultSet = statement.executeQuery("SELECT * FROM STUDENT");
 
        while (resultSet.next()) {
            System.out.println(resultSet.getString("FULLNAME"));
        }
    }
 
}

There is not really much to say. The output I see is:
Koray Tugay
Mick Jagger
Eddie (from Iron Maiden)
Other guy..