Stack Exchange
Cannot Access MySQL database
I just deployed my first "war" file on tomcat. and I was able to open the JSP form from my browser using my network IP address from my own computer. However, when I tried to submit my form I see the following  error message:
'''HTTP Status 500 – Internal Server Error
Type Exception Report

Message java.lang.NullPointerException

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:605)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:515)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

java.lang.NullPointerException
    org.apache.jsp.response_jsp$BondPay.display(response_jsp.java:44)
    org.apache.jsp.response_jsp._jspService(response_jsp.java:178)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.'''

Here is my response.jsp page code. As you can see this is a simple test page and in which the class is implemented within it.
 <%@page import="java.sql.*" %>
    <%Class.forName("com.mysql.jdbc.Driver") ; %>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF- 
    8">
            <title>JSP Page</title>
            <link href="My Resources/font-awesome/css/fontawesome.css" 
    rel="stylesheet" type="text/css"/>
            <link href="My Resources/bootstrap/css/bootstrap.min.css" 
   rel="stylesheet" type="text/css"/>
            <script src="My Resources/jquery/jquery-3.4.1.min.js" 
   type="text/javascript"></script>
        </head>
        <body>
             <%!
            public class BondPay {

    String URL ="jdbc:mysql://localhost:3306/bondrepayments";
    String USERNAME="root";
    String PASSWORD="root";

    Connection connection=null;
    PreparedStatement selectActors=null;
    ResultSet resultSet=null;

    public BondPay(){

    try{

    connection=DriverManager.getConnection(URL,USERNAME,PASSWORD);
    selectBond=connection.prepareStatement("SELECT * FROM repayments WHERE 
    bond_value= ? AND bond_Serial= ? AND currency=?");
    }catch(SQLException e){
    e.printStackTrace();
    }
    }

    public ResultSet display(String amount, String serial,String currency){
    try{
    selectBond.setString(1, amount);
    selectBond.setString(2, serial);
    sselectBond.setString(3, currency);
    resultSet=selectBond.executeQuery();

    }catch(SQLException e){
    e.printStackTrace();
    }
    return resultSet;
    }
    }
      %>
      <%String currency=request.getParameter("currency");
                String serial=request.getParameter("serial");
                String amount=request.getParameter("amount");

       BondPay bondPaid=new BondPay();
            ResultSet res=bondPaid.display(amount,serial,currency);

      %>       

            <div class="table-responsive">
            <table class="table table-striped table-bordered">
                <thead>
                    <tr>
                        <th><h3>Result</h3></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><h4>Place of Issue</h4></td>
                        <td><h4>Bond Serial</h4></td>
                        <td><h4>Bond Holder Name</h4></td>
                        <td><h4>Bond Value</h4></td>
                        <td><h4>Currency</h4></td>
                        <td><h4>Days</h4></td>
                        <td><h4>Interest</h4></td>
                        <td><h4>Principal</h4></td>
                        <td><h4>Total</h4></td>
                        <td><h4>Letter Reference</h4></td>
                    </tr>
                <div class="alert alert-danger" > 
                <strong> <% 
                        if(!res.isBeforeFirst()){
                        out.println("No records found !");}
              else {%></strong></div><%
                        while(res.next()){%>
                    <tr>
                        <td><%= res.getString("location")%></td>
                        <td><%= res.getString("bond_serial")%></td>
                        <td><%= res.getString("bond_holder_name")%></td>
                        <td><%= res.getString("bond_value")%></td>
                        <td><%= res.getString("currency")%></td>
                        <td><%= res.getString("days")%></td>
                        <td><%= res.getString("interest")%></td>
                        <td><%= res.getString("principal")%></td>
                        <td><%= res.getString("total")%></td>
                        <td><%= res.getString("reference")%></td>
                    </tr>
                    <%}}%>
                </tbody>
            </table>
            </div>


Post your code as well .

@Swati, I just added my code below the previous one, can you check it again?

does currency ,amount and serial have required values ? try to print and check.

}catch(SQLException e){
    e.printStackTrace();
    }

This portion of your code basically hides any errors you might have faced while connecting to DB or issue of a query. From the trace its clear that resultSet=selectBond.executeQuery(); statement faced an NPE because selectBond is null. Your DB connection had failed of some error, which might have printed before. Its better to use proper logging or exception raising to understand what exactly went wrong. 
Please try to add the logs to  exception and check what exactly went wrong in your DB connection. I know this is not a perfect answer, but I cannot add these much in a comment :-) 
