主题:新手问题:cannot resolve symbol
binger623
[专家分:0] 发布于 2005-08-03 11:05:00
我是一个java新手,现在遇到了一个问题,请大家帮我看一下:
我做了两个java文件:DBConnection.java(作用是连接数据库);DBSQLMangae.java
(作用是对数据库进行操作).
DBConnection.java是用package bookshop;打成bookshop的包。。
这个文件已编译成功,并生成了DBConnection.class
DBSQLMangae.java是import bookshop.*调用包bookshop中的方法和属性,但是老是有
错误:cannot resolve symbol。我估计意思应该是不能解释所引用的谅和属性吧
我第一java文件不是已经编译成功了吗?到底怎么回事?
另外说明一下我用JSP连接数据库没有做么问题!运行JSP文件都没有问题!
我装的是JBuilder9, 装在D:\JBuilder9下
Tomacat5, 装在D:\Tomcat5.0下
我的目录结构是
文件的根目录D:/Tomcat5.0/jsp-examples/bookshop/
index.jsp
WEB-INF/classes/bookshop/ DBConnection.class
WEB-INF/classes/bookshop/ DBConnection.java
WEB-INF/classes/bookshop/ DBSQLMangae.java
回复列表 (共8个回复)
沙发
lulu6686 [专家分:320] 发布于 2005-08-03 17:23:00
可能是你的classpath配置的问题
板凳
hlnccc [专家分:250] 发布于 2005-08-03 17:43:00
cannot resolve symbol 的意思是你的程序里有的变量没定义就用了,也可以理解为解释不了,一般报这中错的时候,后面还会有一句话告诉你是哪个变量cannot resolve
3 楼
hlnccc [专家分:250] 发布于 2005-08-03 17:45:00
WEB-INF/classes/bookshop/ DBConnection.java
WEB-INF/classes/bookshop/ DBSQLMangae.java
这两个文件位置不对,应该是
WEB-INF/classes/DBConnection.java
WEB-INF/classes/DBSQLMangae.java
经过编译后是
WEB-INF/classes/bookshop/ DBConnection.class
WEB-INF/classes/bookshop/ DBSQLMangae.class
4 楼
binger623 [专家分:0] 发布于 2005-08-04 08:48:00
我的环境变量:
CLASSPATH----------.;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar
JAVA_HOME----------D:\program files\JBuilder9\jdk1.4
PATH---------------D:\program files\JBuilder9\jdk1.4\bin
TOMCAT_HOME--------D:\program files\Tomcat 5.0
5 楼
binger623 [专家分:0] 发布于 2005-08-04 08:51:00
错误提示:
DBSQLManager.java:15 : connot resolve symbol
Symbol:class DBConnectionManager
Location:class bookshop.DBSQLManager
DBConnectionManager dcm=new DBConnectionManager();
^
DBSQLManager.java:15 : connot resolve symbol
Symbol:class DBConnectionManager
Location:class bookshop.DBSQLManager
DBConnectionManager dcm=new DBConnectionManager();
^
DBSQLManager.java:21 : connot resolve symbol
Symbol:variable isConnect
Location:class bookshop.DBSQLManager
IsConnect=false;
^
3 errors
6 楼
binger623 [专家分:0] 发布于 2005-08-04 08:52:00
-----------------------------------------------------------------------------
DBConnectionManager.java
package bookshop; -------------------------------------- (第1行)
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/ --------------------------------------------------------- (第10行)
import java.sql.*;
public class DBConnectionManager{
private String driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver";
private String url="jdbc:microsoft:sqlserver://BINGER:1433;DatabaseName=test";
private String user="test";
private String password="test";
public void setDriverName(String newDriverName){
this.driverName=newDriverName; ---------------------------------------------- (第20行)
}
public String getDrvieraName(){
return driverName;
}
public void setUrl(String newUrl){
this.url=newUrl;
}
public String getUrl(){
return url; ------------------------------------------------ (第30行)
}
public void setUser(String newUser){
this.user=newUser;
}
public String getUser(){
return user;
}
------------------------------------------------------------ (第40行)
public void setPassword(String newPassword){
this.password=newPassword;
}
public String getPassword(){
return password;
}
public Connection getConnection(){
try
{ ----------------------------------------------------------------- (第50行)
Class.forName(driverName);
return DriverManager.getConnection(url,user,password);
}
catch (Exception e){
e.printStackTrace();
return null;
}
}
} ----------------------------------------------------------------- (第60行)
7 楼
binger623 [专家分:0] 发布于 2005-08-04 08:53:00
DBSQLManager.java
package bookshop; ----------- ----------- ----------- ----------- --(第1行)
import java.sql.*;
import bookshop.*;
public class DBSQLManager{
protected Connection conn=null;
protected Statement stmt=null;
protected ResultSet rs=null;
protected String sqlStr;
--------- ----------- ----------- ----------- - (第10行)
public DBSQLManager(){
try {
sqlStr = "";
DBConnectionManager dcm = new DBConnectionManager();----------------- - (出错行第15行)
conn = dcm.getConnection();
stmt = conn.createStatement();
}
catch (Exception e){
System.out.println(e); --------------------------------------------- (第20行)
isConnect=false; ------------------------------------ (出错行第21行)
}
}
public Statement getStmt(){
return stmt;
}
public Connection getConn(){---------------------------------------------- (第30行)
return conn;
}
public ResultSet getRs(){
return rs;
}
public void setSqlStr(String newSqlStr){
this.sqlStr=newSqlStr; ------------------------------------------------- (第40行)
}
public String getSqlStr(){
return sqlStr;
}
public void executeQuery() throws Exception{
rs=stmt.executeQuery(sqlStr);
}
public void executeUpdate() throws Exception{ ---------------- ---------------- ---(第50行)
stmt.executeUpdate(sqlStr);
}
public void close() throws SQLException{
if(stmt!=null){
stmt.close();
stmt=null;
}
conn.close(); -------------------------------------------------------------------- (第60行)
conn=null;
}
};
8 楼
hlnccc [专家分:250] 发布于 2005-08-04 09:22:00
应该是你的两个beans位置的错误,程序没问题,只是说找不到那个类么,环境变量不影响这些的,我没用过jBuilder ,不知道它本身是不是有问题,你按照我说的那个路径放你拿两个程序试试
我来回复