record.jsp

<%@page import="java.sql.*" %>
<%@page import="beans.connection" %>
<%
  try
  {
      Connection con=connection.GetConnection();
      Statement st=con.createStatement();
      String query="select * from empdetail";
      ResultSet rs=st.executeQuery(query);
      ResultSetMetaData rsmd=rs.getMetaData();
      int cols=rsmd.getColumnCount();
%>
      <table>
      <tr>
<%
      for(int i=1;i<=cols;i++)
      {
%>
          <th><%rsmd.getColumnName(i);%></th>
<%
      }
%>
      </tr>
<%
      while(rs.next())
      {
%>
          <tr>
<%
          for(int i=1;i<=cols;i++)
          {
%>
              <td><%rs.getString(i);%></td>
<%
          }
%>
        </tr>
<%
      }
%>
    </table>
<%
  }
  catch (SQLException e)
  {
      e.printStackTrace();
  }
%>

connection.java

import java.sql.Connection;
import java.sql.DriverManager;

public class connection
{
    public static Connection GetConnection()
    {
        @SuppressWarnings("unused")
        Connection con=null;
        try
        {
            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
            con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","hr");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;

    }
}

error

java.lang.NullPointerException
    at org.apache.jsp.record_jsp._jspService(record_jsp.java:61)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    at java.lang.Thread.run(Unknown Source)

hi
this is my program to show table data in jsp but it is not working. help me please

you get a NullPointerException. I assume you know what that is and when that's thrown?
unfortunately, since the line the exception points to, doesn't exist in the code you show, so maybe you have a number of breaks in the file that aren't here?
a few pointers though:
don't use Java code in your jsp files, try to use servlets.
secondly, when it comes to question about jsp and servlets, I think this forum is a bit more suitable.

I do think however, I've spotted your problem:
your getConnection method always return null. see where that might lead to the Exception you've been getting?

yes, and then there's the not closing the database resources when he's done with them and the lowercase classname.

return null;

why are you returning null.It was expecting Connection object to be returned but you are always returning null.
Change this to
return con

Moreover change your approach.Database connectivity must not be on presentation layer.Separate your business,data and presentation layer.More better approach will be to use MVC architecture.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.