应该是dmp.rs.next();//******************************Can't make a static reference to the non-static field

解决方案 »

  1.   


    还要用get获得
    public ResultSet getRS(){
      return this.rs;
    }
    应该是dmp.getRS().next();//******************************Can't make a static reference to the non-static field
      

  2.   

    问题很明显了:
    main是静态方法,引用了非静态变量。你需要在main函数里先实例化一个当前类。再来执行这个类的方法。不要在main里写上逻辑代码
      

  3.   

    /*
     * Created on 2005-1-28
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    package test;
    import java.sql.*;
    public class DatabaseMoreOperation 
    {
    private String dbURL;
    private String user;
    private String password;
    private Statement sta;
    private ResultSet rs;
    public static void main(String[] args)
    {
    try
    {
    DatabaseMoreOperation dmp=new DatabaseMoreOperation();
    String sqlCommand;
        dmp.setURL("jdbc:odbc:sample");
        dmp.setUser("");
        dmp.setPassword("");
        Connection con=dmp.getConnection();
        dmp.setStatement(con);
        sqlCommand="select * from student";     
            ResultSet ts = dmp.setResultSet(sqlCommand);
                ts.next();
    for(int i=0;i<ts.getRow();i++)
    {
    System.out.println(ts.getString("Name"));
    ts.next();
    }
    ts.close();
    //operator.closeStatement();
    con.close();
    }
    catch(Exception e)
    {
    System.out.println(e.toString());
    }
    }

    public void setURL(String dbURL)
    {
    this.dbURL=dbURL;
    }

    public void setUser(String user)
    {
    this.user=user;
    }

    public void setPassword(String password)
    {
    this.password=password;
    }

    public Connection getConnection()
    {
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    return DriverManager.getConnection(dbURL,user,password);
    }
    catch(Exception e)
    {
    System.out.println(e.toString());
    return null;
    }
    }

    public void setStatement(Connection con)
    {
    try
    {
    sta=con.createStatement();
    }
    catch(Exception e)
    {
    System.out.println(e.toString());
    }
    }

    public ResultSet setResultSet(String sql)
    {   
    try
    {
    rs=sta.executeQuery(sql);
    }
    catch(Exception e)
    {
    System.out.println(e.toString());
    }
    return rs;
    }
    }