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!

The import xxx cannot be resolved - Java & JSP

843840Mar 1 2008 — edited Mar 1 2008
Hi everyone,
I have been working on this problem for hours now and can't find a solution.
Basically I have two java files. One which is responsible to establish a connection to the MySQL database and another one which creates the queries. They work fine if I run them directly. However trying to get them working with jsp is a different story...

This is my testconn.jsp file which is located in the root folder:
<%@ page language="java" contentType="text/html" %>
<%@ page session="true" %>
<%@ page import="dbquery" %>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
     <title>Conn Test</title>
  </head>
<body>
This is  a test
<%
dbquery dbq = new dbquery; 
String b_name = dbq.getBName();
out.print(b_name);
 %>
Hope you can see the book name.
</body>
</html>
Now I have this dbquery.java located in WEB-INF/classes:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class dbquery
{
	public static String bName,bPrice;
	public static dbmanager DBM = new dbmanager();
	public static void main (String args[])
	{
		Connection conn = null;
		Statement sm = null;
		ResultSet rs = null;
		try
		{
		conn = DBM.Connect();
		sm = conn.createStatement();
		rs = sm.executeQuery("SELECT * FROM Inventory");
		while(rs.next())
		{
		   bName = rs.getString("Bookname");
		   bPrice = rs.getString("Price");
		   System.out.println(bName+"\t"+bPrice);
		}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		DBM.Disconnect();
	}
	public String getBName()
	{
		return bName;
	}
	
}
For some reason I receive the error:
An error occurred at line: 6 in the generated java file
The import dbquery cannot be resolved
JSP FileName:/testconn.jsp
Java FileName:/C:/Program Files/Apache Software Foundation/Tomcat 5.5/work/Catalina/localhost/_//org/apache/jsp\testconn_jsp.java

Any help would be greatly appreciated!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 29 2008
Added on Mar 1 2008
29 comments
3,522 views