第二句的意思是,用-Xlint重新编译TryBookDB.java 将得到更多的信息
可是用同包中的对象

解决方案 »

  1.   

    两个类的代码如下:
    package mypack;import java.sql.*;
    import java.util.*;public class TryBookDB{
    private String dbUrl="jdbc:mysql://localhost:3306/BookDB";
    private String dbUser="wulirong";
    private String dbPwd="98002129";

    public TryBookDB(){
    try{
    Class.forName("com.mysql.jdbc.Driver");
    }catch(Exception e){
    e.printStackTrace();
    }
    }

    private Connection getConnection() throws Exception{
    return DriverManager.getConnection(dbUrl,dbUser,dbPwd);
    }

    private void closeConnection(Connection conn){
    try{
    if(conn!=null)conn.close();
    }catch(Exception e){
    e.printStackTrace();
    }
    }

    private void closeStatement(Statement stmt){
    try{
    if(stmt!=null)stmt.close();
    }catch(Exception e){
    e.printStackTrace();
    }
    }

    private void closeResultSet(ResultSet rs){
    try{
    if(rs!=null)rs.close();
    }catch(Exception e){
    e.printStackTrace();
    }
    }

    public Collection getBooks(){
    ArrayList books=new ArrayList();
    BookDetails book=null;
    String sql="select * from books";
    Connection conn=null;
    Statement stmt=null;
    ResultSet rs=null;



    try{
    conn=getConnection();
    stmt=conn.createStatement();
    rs=stmt.executeQuery(sql);

    while(rs.next()){
    book=new BookDetails(rs.getString("id"),rs.getString("title"),
    rs.getString("author"),rs.getFloat("price"));
    books.add(book);
    }
    }catch(Exception e){
    e.printStackTrace();
    }finally{
    closeConnection(conn);
    closeStatement(stmt);
    closeResultSet(rs);
    }

    Collections.sort(books);
    return books;
    }
    }package mypack;public class BookDetails{
    private String bookId;
    private String author;
    private String title;
    private float price;

    public BookDetails(String bookId,String author,String title,float price){
    this.bookId=bookId;
    this.author=author;
    this.title=title;
    this.price=price;
    }

    public String getBookId(){
    return bookId;
    }

    public String getAuthor(){
    return author;
    }

    public String getTitle(){
    return title;
    }

    public float getPrice(){
    return price;
    }
    }
      

  2.   

    1.4下没有
    The compiler responds by giving you a warning: Note: GenericArray.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.Those of us who worked with C, especially pre-ANSI C, remember a particular effect of warnings: when you discover you can ignore them, you do. For that reason, it's best to not issue any kind of a message from the compiler unless the programmer must do something about it. 
    In this case, we've gotten a single warning, and we believe that it's about the cast. But if you really want to make sure, you should run - Xlint:unchecked: 
      

  3.   

    Note: TryBookDB.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.这个警告,我搜了一下好像都是1.5下有的
      

  4.   

    应该是1.5的新特性
    我怀疑这边问题:
    finally{
    closeConnection(conn);
    closeStatement(stmt);
    closeResultSet(rs);
    }
    顺序不对
    应该是rs,stmt,conn
      

  5.   

    换了位置后仍旧有note提示!怎么我TryBookDB中不能调用BookDetails?
      

  6.   

    那个提示就别管它了
    你是不是classpath里面没有那个点啊?就是表示当前路径
      

  7.   

    有的,在classpath中在当前路径的