1

I'm working with JSP and Java, I'm getting an error stating DbSettings cannot be resolved.

I have created the class DbSettings and it's in my build folder and DbSettings.java is in my source folder.

Here is the stacktrace:

An error occurred at line: 53 in the jsp file: /currency_form.jsp
DbSettings cannot be resolved
50:         ResultSet rs = null;
51:         String message = null;
52:         try {
53:             rs = DbSettings
54:                     .getResultSet("SELECT BLMBG_CURR_CODE,BLMBG_CURR_NAME FROM AON_CURRENCY_SDO ORDER BY BLMBG_CURR_NAME");
55:             fEmptyRecordset = rs.first();
56:         } catch (Exception ex) {


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:476)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Java Code:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DbSettings {
    private static Connection getConnection() throws Exception {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection conn = null;
        conn = DriverManager.getConnection(
                "jdbc:oracle:thin:@uschduxcls004sg08:xxxx:xxxxx",
            "xxxxx", "xxxx");
        return conn;

    }

    public static final ResultSet getResultSet(String command) throws Exception {
        Connection conn = getConnection();
        Statement stmt = null;
        stmt = conn.createStatement();
        System.out.println("Statement was Succesful");
        ResultSet rs = null;
        rs = stmt.executeQuery(command);
        System.out.println("Query was Succesful");
        return rs;

    }
}

JSP Code: // Declare variables

boolean fEmptyRecordset, fFirstPass, fNeedRecordset;
        int i; // as Integer
        fEmptyRecordset = false;
        fFirstPass = true;
        fNeedRecordset = true;
        ResultSet rs = null;
        String message = null;
        try {
            rs = DbSettings
                    .getResultSet("SELECT BLMBG_CURR_CODE,BLMBG_CURR_NAME FROM AON_CURRENCY_SDO ORDER BY BLMBG_CURR_NAME");
            fEmptyRecordset = rs.first();
        } catch (Exception ex) {
            fEmptyRecordset = true;
            message = ex.getMessage();
        }
        String aMonth = "";
        int aDate, aYear;
        if ("results".compareToIgnoreCase(request.getParameter("action")) == 0) {
            aMonth = request.getParameter("selMonth");
            aDate = Integer.parseInt(request.getParameter("selDate"));
            aYear = Integer.parseInt(request.getParameter("selYear"));
        } else {
            switch (Calendar.getInstance().get(Calendar.MONTH)) {
            case Calendar.JANUARY:
                aMonth = "JAN";
            case Calendar.FEBRUARY:
                aMonth = "FEB";
            case Calendar.MARCH:
                aMonth = "MAR";
            case Calendar.APRIL:
                aMonth = "APR";
            case Calendar.MAY:
                aMonth = "MAY";
            case Calendar.JUNE:
                aMonth = "JUN";
            case Calendar.JULY:
                aMonth = "JUL";
            case Calendar.AUGUST:
                aMonth = "AUG";
            case Calendar.SEPTEMBER:
                aMonth = "SEP";
            case Calendar.NOVEMBER:
                aMonth = "NOV";
            case Calendar.DECEMBER:
                aMonth = "DEC";
            }
            aDate = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
            aYear = Calendar.getInstance().get(Calendar.YEAR);
        }
        if (message != null || fEmptyRecordset) {
            out.println("<tr><td>");
            out.println(message);
            out.println("</td></tr>");
    %>
POPEYE1716
  • 79
  • 11

2 Answers2

0

Check that you have correctly imported DBSetting class in your JSP.

It is possible to use import statements in JSPs, but the syntax is a little different from normal Java.

This one is a page directive. The page directive can contain the list of all imported packages. To import more than one item, separate the package names by commas, e.g.

General Syntax :

<%@ page import="package1.myClass1,package2.myClass2,....,packageN.myClassN" %>

atish shimpi
  • 4,873
  • 2
  • 32
  • 50
0

You have to either use fully qualified class name or add import for the DBSettings class

for eg. to import List class

<%@ page import="java.util.List" %>
Akash Yadav
  • 2,411
  • 20
  • 32