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 8465555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:05:02+00:00 2026-06-10T15:05:02+00:00

I am currently doing JUnit test for my hospital administration System. But When Attempt

  • 0

I am currently doing JUnit test for my hospital administration System. But When Attempt to check the boolean value of the insertDoctor Method Null Point Exception Came in JUnit Test. That point Statement stmt=con.createStatement. I Have attached all the Code Below. Pl check it.

public class JUnitTest extends TestCase {
    private Connection con;
    public JUnitTest(String testName) {
        super(testName);
        con=DBConnector.getConnection();
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }
    // TODO add test methods here. The name must begin with 'test'. For example:
    // public void testHello() {}
    public void testdeltePatient() throws SQLException{

        Patients p=new Patients();
       assertEquals(true, p.removePatient(333));

    }
    public void testdeleteDoctor() throws SQLException{

        Doctors d=new Doctors();
       d.setSpeciality("General");
       d.setSumOfQn("MBBS");
       d.setExp("3 Years");


        d.setDocId(678);
        d.setEmpId(4344);

        assertEquals(true, d.insertDoctor(d));
    }
}

enter image description here


public class Doctors extends Employee  {

    private int docId;
    private String exp;
    private String sumOfQn;
    private int empId;
    private String speciality;
    private Connection con;

    public String getSpeciality() {
        return speciality;
    }

    public void setSpeciality(String speciality) {
        this.speciality = speciality;
    }

    public Doctors() {

        con = DBConnector.getConnection();
    }

    public int getDocId() {
        return docId;
    }

    public void setDocId(int docId) {
        this.docId = docId;
    }

    public String getExp() {
        return exp;
    }

    public void setExp(String exp) {
        this.exp = exp;
    }

    public String getSumOfQn() {
        return sumOfQn;
    }

    public void setSumOfQn(String sumOfQn) {
        this.sumOfQn = sumOfQn;
    }

    @Override
    public int getEmpId() {
        return empId;
    }

    @Override
    public void setEmpId(int empId) {
        this.empId = empId;
    }

    public Connection getCon() {
        return con;
    }

    public void setCon(Connection con) {
        this.con = con;
    }

    public ResultSet getEmployeeId() throws SQLException {

        ResultSet rs;
        String query = "select * from employee";
        Statement stmt = con.createStatement();
        rs = stmt.executeQuery(query);

        return rs;

    }

    public boolean insertDoctor(Doctors d) throws SQLException {


        PreparedStatement ps;
        boolean result = false;
        **Statement stmt = con.createStatement();**

        String query = "INSERT INTO doctors VALUES ('" + d.getDocId() + "','" + d.getSpeciality() + "','" + d.getExp() + "','" + d.getEmpId() + "',' " + d.getSumOfQn() + "')";
        ps = con.prepareStatement(query);
        int res = ps.executeUpdate();
        if (res > 0) {
            result = true;
        }

        return result;                       
    }
}
  • 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-10T15:05:04+00:00Added an answer on June 10, 2026 at 3:05 pm
    Statement stmt = con.createStatement();
    

    Here con is null.
    Now the value of con is being set at constructor. which says

    con = DBConnector.getConnection();
    

    So definitely, DBConnector.getConnection() is returning null. You have to instantiate DBConnector() in the Junit. Give more information about DBConnector

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently doing a test plan for a system. May I know what are the
I'm currently doing the following to compensate for boolean's not mapping well to radio
I am new to jUnit and Selenium. Currently, we are doing a POC in
Currently doing a test-app with JCR (Modeshape). The abstracted flow is as follows: session.open,
I am currently doing it like this.. but it gets actually stored as integer..
I am currently doing a system on Google App Engine and am very new
I am trying to test my gwt app with gwt junit but seems to
Im currently doing a console app that has to send scheduled emails. In one
I'm currently doing facebook integration and have gone through this tutorial . So far,
I am currently doing a project in which I have to request data from

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.