编译出错:找不到符号

galiton 2006-02-09 06:13:27

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;
}
}

}
...全文
225 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
galiton 2006-02-17
  • 打赏
  • 举报
回复
up
galiton 2006-02-13
  • 打赏
  • 举报
回复
up
congliu 2006-02-11
  • 打赏
  • 举报
回复
javac -classpath DB.class所在的路径 News.java
kelinwang19 2006-02-10
  • 打赏
  • 举报
回复
不懂java,up
IT佬 2006-02-10
  • 打赏
  • 举报
回复
应该与包有关系 好好查看一下。
scottwhb 2006-02-10
  • 打赏
  • 举报
回复
把DB.class的路径添加到classpath中
galiton 2006-02-09
  • 打赏
  • 举报
回复
up
yuzl32 2006-02-09
  • 打赏
  • 举报
回复
有包情况下编译应该使用
javac -d . filename.java (-d 后面的'点' 代表生成当前包目录)
galiton 2006-02-09
  • 打赏
  • 举报
回复
加进去也没用,应该不是这个问题
Samland 2006-02-09
  • 打赏
  • 举报
回复
是啊,你的DB都没有声明
不但要把DB.class放到路径中,还要import它,除非他在当前package中
Paripatetic 2006-02-09
  • 打赏
  • 举报
回复
把DB.class的路径添加到classpath中

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧