Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Meet and Greet (http://www.go4expert.com/community/meet-and-greet/)
-   -   jsp (http://www.go4expert.com/community/jsp-t19667/)

jramprasad 5Oct2009 11:23

jsp
 
Apache Tomcat/5.5.28 - Error reporthi good AM to every one

this is my jsp code
HTML Code:

<%@ page language="java" contentType="text/html"%>
<%@ page import="connjsp.jspconn"%>
<%@ page import="java.sql.ResultSet"%>

<html>
<body>

<br>
<br>
<table align="center" border="3">

<tr><td>Name </td></tr>
<%
    ResultSet rs;
    jspconn js = new jspconn();
    rs=js.viewdata();

while( rs.next())
    {
   
  String rd=rs.getString(1);
out.println("rd");
   
    }%>

   
 <tr><td><% out.println(rs.getString(1)); %></td></tr>

</table>
</body>
</html>

My java file
Code:

package connjsp;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;

public class jspconn
{


String sql;
Connection connection;
Statement stmt;
ResultSet rs;

    public ResultSet viewdata()
    {


    try {

       
       
        // Load the JDBC driver
        String driverName = "oracle.jdbc.driver.OracleDriver";
        Class.forName(driverName);

// Create a connection to the database
        String serverName = "localhost";
        String portNumber = "1521";
        String sid = "TEST";
        String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
        String username = "MANAGER";
        String password = "ORACLE";
        connection = DriverManager.getConnection(url, username, password);
    System.out.println("connected");
      stmt=connection.createStatement();
      sql="select * from emp";
      rs=stmt.executeQuery(sql);
     

    } catch (ClassNotFoundException e) {
        // Could not find the database driver
    } catch (SQLException e) {
        // Could not connect to the database
    }
      return rs;
    }
}


Executing my jsp code the following errors will thrown. Please anybody knows the solution please forward me .



type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:460) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:373) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet .java:729)
root cause
java.lang.NullPointerException org.apache.jsp.showemp_jsp._jspService(showemp_jsp .java:61) org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:98) javax.servlet.http.HttpServlet.service(HttpServlet .java:729) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:331) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet .java:729)


All times are GMT +5.5. The time now is 17:52.