I have the following code and I am trying to create a connection to a database.
I get an error "*Could not find or load main class onjava*" when I run the command: *java -cp . onjava*

I am able to run the *javac -classpath "C:\CATALINA\_HOME\lib\*" onjava.java* command
Both of my .class and .java files are in the same directory WEB-INF\classes\com\onjava

**onjava.java**

```
package com.onjava;
import java.sql.*;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.*;

import javax.naming.Context;

public class onjava extends HttpServlet {

  private DataSource datasource;

  public void init(ServletConfig config) throws ServletException {
    try {
      // Look up the JNDI data source only once at init time
      Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
      datasource = (DataSource) ((InitialContext) envCtx).lookup("jdbc/testdb");
    }
    catch (NamingException e) {
      e.printStackTrace();
    }
  }

  private Connection getConnection() throws SQLException {
    return datasource.getConnection();
  }

  public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException {
    Connection connection=null;
    try {
      connection = getConnection();
      //..<do JDBC work>..
      if (connection != null) {

            String message = "You are connected!";
            System.out.println(message);

        } else {
            System.out.println("Failed to make connection!");
        }
    } 
    catch (SQLException sqlException) {
      sqlException.printStackTrace();
    }
    finally {
      if (connection != null) 
        try {connection.close();} catch (SQLException e) {}
      }
    }
  }

```

**EDIT:**

I changed my code and I added the public class. But I am facing the same error when I run it!

```
package src;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Wrapper;
import java.util.Hashtable;
import java.util.Properties;
import java.io.*;
import javax.activation.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import oracle.jdbc.pool.OracleDataSource;

public class onjava {

    public static void main(String[] argv) throws SQLException, NamingException {

        Properties prop = new Properties();
        System.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.naming.java.javaURLContextFactory");
        Context initialContext = new InitialContext(prop);
        if ( initialContext == null){
              System.out.print("JNDI problem. Cannot get InitialContext.");
        } else {System.out.print("NO JNDI problemb ");}

        // Get DataSource
        Context envContext = (Context)initialContext.lookup("java:/comp/env");
        DataSource ds = (DataSource)envContext.lookup("jdbc/testdb");

        System.out.println("\n -------- Oracle JDBC Connection Testing ------");

        try {

            Connection jdbcConnection = ((Statement) ds).getConnection();
            OracleDataSource ods = ((Wrapper) ds).unwrap(OracleDataSource.class);
            jdbcConnection.close();

        } catch (SQLException e) {

            System.out.println("Connection Failed! Check output console");
            e.printStackTrace();
            return;

        }

        String message = "You are connected!";
        System.out.println(message);

    }

}

```