C:\Documents and Settings\Administrator>javac "C:\Program Files\Apache Software
Foundation\Tomcat 5.5\webapps\news\WEB-INF\classes\News.java"
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\news\WEB-INF\clas
ses\News.java:74: 找不到符号
符号: 类 DB
位置: 类 StudyNews.News
        public boolean Insert(DB db) throws Exception{错误箭头指向 DB
----------------------------------------------------------------------------
源代码如下:package StudyNews;import java.util.*;
import java.sql.ResultSet;public class News{

protected int id;
protected String title ;
protected String content;
protected String author;
protected String time;
protected String keyword ;
protected int type;

public News(){ }

public void setId(int id) {
this.id = id;
}

public void setTitle(String title) {
this.title = title;
}

public void setContent(String content) {
this.content = content;
}

public void setAuthor(String author) {
this.author = author;
}

public void setTime(String time) {
this.time = time;
}

public void setKeyword(String keyword) {
this.keyword = keyword;
}

public void setType(int type) {
this.type = type;
}

public int getId(){
return id;
}

public String getTitle(){
return title;
}

public String getContent(){
return content;
}

public String getAuthor(){
return author;
}

public String getTime(){
return time;
}

public String getKeyword(){
return keyword;
}

public int getType(){
return type;
}

public boolean Insert(DB db) throws Exception{
        String strSql;
ResultSet rs;
int iMaxId;
        strSql = "Select max(id) From news";
rs = db.OpenSql(strSql);  
if ( rs.next()) {
iMaxId=rs.getInt(1)+1;
}
else{
iMaxId=1;
}
        
        strSql = "insert into news values(" 
         + iMaxId  +",'"
+ title  +"','"
+ content  +"','"
+ author  +"',sysdate,'"
+ keyword  +"',"
+ type +")";
if ( db.ExecSql(strSql)==0) {
return false;
}
else{
return true;
}

}

public  boolean Edit(DB db) throws Exception{
        String strSql;
        strSql = "update news set title='"+title+"',"
         + " content='"+ content +"',"
         + " author='"+ author +"',"
         + " keyword='"+ keyword +"',"
         + " type="+ type
         + " where id="+id;
if ( db.ExecSql(strSql)==0) {
return false;
System.out.println("数据连接失败");
}
else{
return true;
}
}

public static Vector SearchNewsTitle(DB db) throws Exception{
Vector newsList = new Vector();
ResultSet rs,rsNest;
        String strSql=null;

        strSql = "select * from news order by time desc";
rs = db.OpenSql(strSql);

while  (rs.next()){
News news = new News();

news.setId(rs.getInt("id")) ;
news.setTitle(rs.getString("title")) ;
news.setTime(rs.getString("time")) ;
news.setType(rs.getInt("type")) ;

newsList.add(news);
}
System.out.println("newsList:        "+newsList.size());

return newsList;
}

public static Vector SearchRelativeNews(DB db,int newsId,String keyword) throws Exception{
Vector newsList = new Vector();
ResultSet rs,rsNest;
        String strSql=null;

        strSql = "select * from news where id<>" + newsId +" and title like '%" 
         + keyword + "%' order by time desc";
rs = db.OpenSql(strSql);

while  (rs.next()){
News news = new News();

news.setId(rs.getInt("id")) ;
news.setTitle(rs.getString("title")) ;
news.setTime(rs.getString("time")) ;

newsList.add(news);
}
System.out.println("newsList:        "+newsList.size());

return newsList;
}

public static News GetDetail(DB db,int newsId,boolean bEdit) throws Exception{
Vector newsList = new Vector();
ResultSet rs,rsNest;
        String strSql=null;
        String rplContent=null;

        strSql = "select * from news where id = " + newsId ;
rs = db.OpenSql(strSql);
News news = new News();
if (rs.next()){

news.setId(newsId) ;
news.setTitle(rs.getString("title")) ;
news.setAuthor(rs.getString("author")) ;

rplContent = rs.getString("content");

if(!bEdit){
rplContent = rplContent.replaceAll("\n","<br>");
}
news.setContent(rplContent) ;
news.setTime(rs.getString("time")) ;
news.setKeyword(rs.getString("keyword")) ;
news.setType(rs.getInt("type")) ;
}
return news;
}

public static boolean Delete(DB db,int newsId) throws Exception{
        String strSql;
        strSql = "delete from news where id='"+newsId+"'";
if ( db.ExecSql(strSql)==0) {
return false;
}
else{
return true;
}
}

}

解决方案 »

  1.   

    把DB.class的路径添加到classpath中
      

  2.   

    是啊,你的DB都没有声明
    不但要把DB.class放到路径中,还要import它,除非他在当前package中
      

  3.   

    有包情况下编译应该使用
    javac -d . filename.java (-d 后面的'点' 代表生成当前包目录)
      

  4.   

    把DB.class的路径添加到classpath中
      

  5.   

    javac -classpath DB.class所在的路径 News.java