我正在使用JSP和Java,我收到错误声明无法解析DbSettings。
我已经在我的构建文件夹中创建了类DbSettings,而DbSettings.java位于我的源文件夹中。
这是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代码:
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代码: //声明变量
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>");
%>
答案 0 :(得分:0)
检查您是否在JSP中正确导入了DBSetting
类。
可以在JSP中使用import
语句,但语法与普通Java略有不同。
这是page directive
。 page指令可以包含所有导入包的列表。要导入多个项目,请用逗号分隔包名称,例如
一般语法:
<%@ page import="package1.myClass1,package2.myClass2,....,packageN.myClassN" %>
答案 1 :(得分:0)
您必须使用完全限定的类名或为DBSettings类添加导入
例如。导入List类
<%@ page import="java.util.List" %>