Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

org.apache.jasper.JasperException: Unable to compile class for JSP: cannot be resolved to a variable

 
Aditi Joshi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am getting this error while accessing java variable in jsp. Please help. Following is my code.

<%
int num;
try{

String enquiry_no;
ResultSet rs=null;
String url = "jdbc:mysql://localhost:3306/test";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url, "root", "root");
Statement statement = connection.createStatement();

String query = "select id from employee_table";

rs = statement.executeQuery(query);
rs.last();
num=rs.getRow();
int rowCount=num+1;;
emp_id=Integer.toString(rowCount);

System.out.println(emp_id);

}
catch(SQLException e){e.printStackTrace();}
%>
<tr>
<td width="134">Enquiry Number - </td>
<td colspan="2"><input type="text" name="emp_id" value="<%=emp_id%>" readonly="readonly" /></td>
</tr>


Thanks in Advance.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. the cannot resolved variable is emp_id ? if yes define as you defined num .

2. why do you depends on row count for your employee id. you will endup with same employee id for different employees.
for example: employee_id is 10 now . then somebody remove some employee(say 5th employee) now rowcount become 9.
=> when you enter new employee he will get 10 again!

3.please move your db/java code to a java class.WhyNotUseScriptlets
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Aditi Joshi :)
 
Aditi Joshi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lott sir....it worked....also thanks for suggesting logic...:-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic