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)