0

I am getting java.lang.nullpointer exception for this code plzz help me out all database linked programs are creating same error

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class retser extends HttpServlet {
    Connection c;
    Statement st;
    ResultSet rs;
    ServletConfig config;

    public void init() {
        config = getServletConfig();
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "tiger");
            Statement st = c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
            rs = st.executeQuery("select * from book");
        } catch (Exception e) {
        }
    }//end init

    public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        PrintWriter pw = res.getWriter();
        try {
            int x = Integer.parseInt(req.getParameter("t1"));
            pw.println(x);
            rs.next();
            pw.println(rs.getInt(1));
//+"  "+rs.getString(2)+"  "+rs.getInt(3)		
        } catch (Exception e) {
            pw.println(e);
        }
    }
}

Edited by peter_budo: Correcting code indentation.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by stultuske
0

and what are you getting a nullpointer on? since we don't have your complete code, nor access to the resources you are using, you don't think we'll be able to reproduce your error, do you?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.