Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8214623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:31:12+00:00 2026-06-07T11:31:12+00:00

I have developed the below program but it is throwing null pointer exception. Below

  • 0

I have developed the below program but it is throwing null pointer exception.

Below is the model class..

public class Circle {

    private int Id;
    public Circle(int id, String name) {
        super();
        Id = id;
        this.name = name;
    }
    private String name;
    public int getId() {
        return Id;
    }
    public void setId(int id) {
        Id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

}

Below is the dao class..

public class jdbcdaoimpl {
    public Circle getCircle(int circleId) 
        {   
        Circle circle = null;

        try
        {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","saral","saral");
        PreparedStatement stmt=con.prepareStatement("select * from CIRCLE where id = ?");
        stmt.setInt(1,circleId);
        ResultSet rset=stmt.executeQuery();
        while(rset.next())
        {
             circle= new Circle(circleId, rset.getString("name") );
        }       
        rset.close();
        stmt.close();
        con.close();
        }                   
        catch (Exception e)
        {
            e.printStackTrace();            
        }
        return circle;
    }
}

and finally the main class..

public class jdbcDemo {

    public static void main(String[] args) {
        Circle c = new jdbcdaoimpl().getCircle(1);
        System.out.println(c.getName());
    }

}

please advise as on execution of main class it is throwing the null pointer exception.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:31:13+00:00Added an answer on June 7, 2026 at 11:31 am

    You are swallowing all exceptions in the DAO method. It returns null. It will also return null if the query simply returns an empty result.

    You also fail to close your resources in a finally. You must propagate your exceptions, not catch them without handling.

    public class JdbcDaoImpl
    {
      public Circle getCircle(int circleId) {
        Connection con = null;
        try {
          Class.forName("oracle.jdbc.driver.OracleDriver");
          con = DriverManager.getConnection(
              "jdbc:oracle:thin:@localhost:1521:xe","saral","saral");
          final PreparedStatement stmt = con.prepareStatement(
              "select * from CIRCLE where id = ?");
          stmt.setInt(1,circleId);
          final ResultSet rset = stmt.executeQuery();
          if (rset.next()) return new Circle(circleId, rset.getString("name") );
          throw new RuntimeException("Result set is empty");
        }
        catch (RuntimeException e) { throw e; }
        catch (Exception e) { throw new RuntimeException(e); }
        finally { try { if (con != null) con.close(); } catch (Throwable t) {} }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed below which makes the use of comparator.. this my pojo.. class
In case of static method overriding ..I have developed this below code class Ab
i have been developed my last project like below as by last architecture View
I have developed below plug-in (function($) { $.fn.addressSearch = function(settings) { settings = jQuery.extend({
I have developed an application which creates an outlook application using outlook object model.
I have developed one console application and use WMI query as per below queryCollection
I have a php program i have developed on the internet. So far i
I have developed a below code based on the concept of immutability , as
I have just started to develop the form below and I have the following
I want to develop cross platform mobile app. I have seen frameworks listed below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.