2022年javac编译找不到符 .pdf
javac 编译找不到符号问题描述:javac course.java course.java:31:找不到符号符号:类sqlBean 位置:类bean.course sqlBean db=new sqlBean;course.java和 sqlBean.java及其他一些文件同放于bean 文件夹下course.java:package bean;import java.sql.*;public class course private String id;private String name;private String dep;private String prepare;private int mark;public void setPrepare(String s)prepare=s;public String getPrepare()return prepare;public void setMark(int s)mark=s;public int getMark()return mark;public void setDep(String s)dep=s;public String getDep()return dep;public String getId()return id;public void setId(String id)this.id=id;public String getName()return name;名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 7 页 -public void setName(String name)this.name=name;public ResultSet getPrepares()/得到所能选择的预修课String sql=select name,id from course;sqlBean db=new sqlBean();ResultSet rs=db.executeQuery(sql);return rs;public String getPrepareDep()/察看预修课所在系String s=no;String sql=select dep from course where id=prepare ;sqlBean db=new sqlBean();try ResultSet rs=db.executeQuery(sql);if(rs.next()s=rs.getString(dep);catch(Exception e)e.getMessage();return s;public ResultSet getCourse()/察看所有课程String sql=select*from course;sqlBean db=new sqlBean();ResultSet rs=db.executeQuery(sql);return rs;public int deleteCourse(String id)int num=0;String sql=delete from Course where id=id ;sqlBean db=new sqlBean();num=db.executeDelete(sql);名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 7 页 -return num;public String getPrepareDep(String id)String dep=;String sql=select dep from course where id=id;sqlBean db=new sqlBean();try ResultSet rs=db.executeQuery(sql);if(rs.next()dep=rs.getString(dep);catch(SQLException e)System.out.print(e.toString();return dep;public void updateCourse(String id)String sql=update course set name=name,prepare=prepare,dep=dep,mark=mark where id=id ;sqlBean db=new sqlBean();db.executeInsert(sql);public void addCourse()String sql=insert into course(id,name,mark,prepare,dep)VALUES(id,name,mark,prepare,dep);sqlBean db=new sqlBean();db.executeInsert(sql);public boolean hasLogin(String id)boolean f=true;String sql=select id from course where id=id ;sqlBean db=new sqlBean();try 名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 7 页 -ResultSet rs=db.executeQuery(sql);if(rs.next()f=false;catch(Exception e)e.getMessage();return f;sqlBean.java:package bean;import java.io.*;import java.sql.*;public class sqlBean/public Connection conn=null;public ResultSet rs=null;private String DatabaseDriver=sun.jdbc.odbc.JdbcOdbcDriver;/DataSource 数据源名称DSN private String DatabaseConnStr=jdbc:odbc:ClassDB2,sa,;/定义方法/*setXxx 用于设置属性值;getXxx 用于得到属性值*/public void setDatabaseDriver(String Driver)this.DatabaseDriver=Driver;public String getDatabaseDriver()return(this.DatabaseDriver);public void setDatabaseConnStr(String ConnStr)this.DatabaseConnStr=ConnStr;public String getDatabaseConnStr()return(this.DatabaseConnStr);名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 7 页 -public sqlBean()/构造函数try Class.forName(DatabaseDriver);catch(java.lang.ClassNotFoundException e)System.err.println(加载驱动器有错误:e.getMessage();System.out.print(执行插入有错误:e.getMessage();/输出到客户端 public int executeInsert(String sql)int num=0;try conn=DriverManager.getConnection(jdbc:odbc:ClassDB,sa,);Statement stmt=conn.createStatement();num=stmt.executeUpdate(sql);catch(SQLException ex)System.err.println(执行插入有错误:ex.getMessage();System.out.print(执行插入有错误:ex.getMessage();/输出到客户端 CloseDataBase();return num;/display data public ResultSet executeQuery(String sql)rs=null;try conn=DriverManager.getConnection(jdbc:odbc:ClassDB,sa,);Statement stmt=conn.createStatement();rs=stmt.executeQuery(sql);名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 7 页 -catch(SQLException ex)System.err.println(执行查询有错误:ex.getMessage();System.out.print(执行查询有错误:ex.getMessage();/输出到客户端 return rs;/delete data public int executeDelete(String sql)int num=0;try conn=DriverManager.getConnection(jdbc:odbc:ClassDB,sa,);Statement stmt=conn.createStatement();num=stmt.executeUpdate(sql);catch(SQLException ex)System.err.println(执行删除有错误:ex.getMessage();System.out.print(执行删除有错误:ex.getMessage();/输出到客户端 CloseDataBase();return num;/public void CloseDataBase()try conn.close();catch(Exception end)System.err.println(执行关闭Connection 对象有错误:end.getMessage();System.out.print(执行执行关闭Connection对象有错误:有错误:end.getMessage();/输出到客户端 名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 7 页 -到 bean文件夹所在目录去编译:javac bean/course.java 或者javac bean/*.java 因为 package 写着是bean 那这两个文件就应该在bean文件夹下面。运行也一样在bean所在文件夹:java bean.course 名师资料总结-精品资料欢迎下载-名师精心整理-第 7 页,共 7 页 -