Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

org.apache.jasper.JasperException: Unable to compile class for JSP:

891428Sep 29 2011 — edited Sep 29 2011
Hii,

Any idea on this error?

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 16 in the jsp file: /1d0258c2440a8d19e716292b231e3190/delete_item_action.jsp
Db.db cannot be resolved to a type
13: for(int i=0; i<count;i++)
14: {
15: if(request.getParameter("checkbox_"+i).equals("delete"))
16: Db.db.setUpdate("Update hardware set d_status=1 where hardware_Id="+request.getParameter("Id_"+i)+";");
17:
18:
This post has been answered by EJP on Sep 29 2011
Jump to Answer

Comments

EJP
So Db.db cannot be resolved to a type.

Did you forget to declare it? or omit an import?
891428
Hi,

I have done the following at the top of the page. Do I miss out something?

<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page language="java" import="DB.*" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
EJP
So where is the declaration of Db.db? Or Db itself for that matter?
891428
The page is located at web/test/test.jsp and the java as below
Is there anything still need to add to test.jsp?

DB.java (web/classes/DB/db.class)
------------------------------------------------------------------------------
package DB;
import java.sql.*;

public class db
{
String db_url="jdbc:mysql://localhost:3306/DB";
String db_user="root";
String db_password="123456";
private ResultSet r=null;
static private ResultSet res=null;
int staff_Id=0;

/** Creates a new instance of db */

public int getRetrieveId()
{
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch (Exception E)
{
E.printStackTrace();
}
try{
Connection C = DriverManager.getConnection(db_url,db_user,db_password);
Statement S = C.createStatement();
r = S.executeQuery("select max(staff_Id) from staff");
while(r.next()){
staff_Id=r.getInt(1);
}
S.close();
C.close();

}
catch(Exception e)
{
e.printStackTrace();
}
return staff_Id;
}

public static boolean getSearch(String s)
{
String search_db_url="jdbc:mysql://localhost:3306/DB";
String search_db_user="root";
String search_db_password="123456";
String str=null;
boolean result=false;

try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch (Exception E)
{
E.printStackTrace();
}
try{
Connection C = DriverManager.getConnection(search_db_url,search_db_user,search_db_password);
Statement S = C.createStatement();
res = S.executeQuery(s);
while(res.next()){
str=res.getString(1);
}
if(!str.equals(null))
{
result=true;
}
S.close();
C.close();

}
catch(Exception e)
{
e.printStackTrace();
}
return result;
}


public void setUpdate(String str)
{
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch (Exception E)
{
E.printStackTrace();
}
try{
Connection C = DriverManager.getConnection(db_url,db_user,db_password);
Statement S = C.createStatement();
int r = S.executeUpdate(str);
S.close();
C.close();

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

}
EJP
Answer
Java is case sensitive, didn't you know that? DB amd Db are two different things to Java, and a class called db must be in a file called db.java; conversely a file called DB.java must contain a class called DB. You need to sort all this out, it is a complete mess at the moment.
Marked as Answer by 891428 · Sep 27 2020
1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 27 2011
Added on Sep 29 2011
5 comments
440 views