Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. java servlet - error HTTP 500 - java.lang.nullpointer exception

java servlet - error HTTP 500 - java.lang.nullpointer exception

Scheduled Pinned Locked Moved Java
helpjavadatabasequestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    golisarmi
    wrote on last edited by
    #1

    I'm working on a servelet project. I use database connection (jdbc odbc) when I try to access data into database, I get HTTP status 500 error java.lang.NullPointerException checkpps.doGet(checkpps.java:61) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) line 61 in my code is : statement = link.createStatement(); any body could help me please???

    D 1 Reply Last reply
    0
    • G golisarmi

      I'm working on a servelet project. I use database connection (jdbc odbc) when I try to access data into database, I get HTTP status 500 error java.lang.NullPointerException checkpps.doGet(checkpps.java:61) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) line 61 in my code is : statement = link.createStatement(); any body could help me please???

      D Offline
      D Offline
      David Skelly
      wrote on last edited by
      #2

      At the risk of stating the obvious, link is null. More than that I cannot say, because I don't know what link is or how you get hold of it.

      G 1 Reply Last reply
      0
      • D David Skelly

        At the risk of stating the obvious, link is null. More than that I cannot say, because I don't know what link is or how you get hold of it.

        G Offline
        G Offline
        golisarmi
        wrote on last edited by
        #3

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

        public class checkpps extends HttpServlet{

        private Statement statement;
        private Connection link;
        private String URL = "jdbc:odbc:quiz";
        String name;

        public void init() throws ServletException
        {

        super.init();
        try{
         
         //load & register drive
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        // get a connection to database
        link = DriverManager.getConnection("jdbc:odbc:quiz","sara", "sara");	
        }
        
        //catch (Exception e)
        //{
        //e.printStackTrace();
        //System.exit(1);
        //}
        
        
        catch (ClassNotFoundException e1){
        System.out.println("driver not found");
        }
        
        catch (SQLException e2){
         System.out.println("error in connection");
        // handle error getting connection}
        }
        //finally{
        //try{
        // close the connection to release db resources	
        //if (link!=null) link.close(); // conn closed?    
        //}	
        //catch (SQLException e3){  }	// ignored
        

        //}
        }

        public void doGet (	HttpServletRequest req,			
        HttpServletResponse res) throws ServletException, IOException {
        	
        	res.setContentType ("text/html");	
        	PrintWriter out= res.getWriter();
        	
        	String city = req.getParameter("city");
            String ppsnum = req.getParameter("ppsno");
        	
        	try {
           
             statement = link.createStatement();
        	 ResultSet result = statement.executeQuery("SELECT \* FROM player");
        	 //statement.close();
        	 //String pps = result.getString("ppsno");
        	//if (!result.wasNull()) {
        	//res.sendRedirect("youPlayed");
        	//}
           //}//end try  
           
           while(result.next())
           {
           out.println("<p>" + result.getString("ppsno"));
           }
           }
        	 catch (SQLException e)
        	 {
        	 System.out.println("error statement");
        	 }
        	
        	}
        	
        	public void destroy()
        {
        try {
        link.close();
        }
        catch (Exception e) {
        System.out.println("error on closing!!");
        e.printStackTrace();
        System.exit(1);
        }
        }
        	}
        

        as you see in my code, I'm trying to connect to database (MS Access) and link is my connection name. seems my connection has problem for some reason but still couldn't solve it. I have created DSN by the way. any help?

        modified on Wednesday, November 11, 2009 8:51 AM

        S 1 Reply Last reply
        0
        • G golisarmi

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

          public class checkpps extends HttpServlet{

          private Statement statement;
          private Connection link;
          private String URL = "jdbc:odbc:quiz";
          String name;

          public void init() throws ServletException
          {

          super.init();
          try{
           
           //load & register drive
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          // get a connection to database
          link = DriverManager.getConnection("jdbc:odbc:quiz","sara", "sara");	
          }
          
          //catch (Exception e)
          //{
          //e.printStackTrace();
          //System.exit(1);
          //}
          
          
          catch (ClassNotFoundException e1){
          System.out.println("driver not found");
          }
          
          catch (SQLException e2){
           System.out.println("error in connection");
          // handle error getting connection}
          }
          //finally{
          //try{
          // close the connection to release db resources	
          //if (link!=null) link.close(); // conn closed?    
          //}	
          //catch (SQLException e3){  }	// ignored
          

          //}
          }

          public void doGet (	HttpServletRequest req,			
          HttpServletResponse res) throws ServletException, IOException {
          	
          	res.setContentType ("text/html");	
          	PrintWriter out= res.getWriter();
          	
          	String city = req.getParameter("city");
              String ppsnum = req.getParameter("ppsno");
          	
          	try {
             
               statement = link.createStatement();
          	 ResultSet result = statement.executeQuery("SELECT \* FROM player");
          	 //statement.close();
          	 //String pps = result.getString("ppsno");
          	//if (!result.wasNull()) {
          	//res.sendRedirect("youPlayed");
          	//}
             //}//end try  
             
             while(result.next())
             {
             out.println("<p>" + result.getString("ppsno"));
             }
             }
          	 catch (SQLException e)
          	 {
          	 System.out.println("error statement");
          	 }
          	
          	}
          	
          	public void destroy()
          {
          try {
          link.close();
          }
          catch (Exception e) {
          System.out.println("error on closing!!");
          e.printStackTrace();
          System.exit(1);
          }
          }
          	}
          

          as you see in my code, I'm trying to connect to database (MS Access) and link is my connection name. seems my connection has problem for some reason but still couldn't solve it. I have created DSN by the way. any help?

          modified on Wednesday, November 11, 2009 8:51 AM

          S Offline
          S Offline
          sparlay_pk
          wrote on last edited by
          #4

          Which MSOffice you are using. And r you sure that you have selected the correct driver type.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups