我写了一个程序,有这样的错误: can not make a static reference to a static method public class myStatement  {

public void mySetString(int parameterIndex1,String x){
PreparedStatement.setString(parameterIndex1, x);  //这里有错误,

}
}现在我想问,我没有声明这个类是静态的,怎么就成了静态的了?PreparedStatement 这个方法是import的包里的方法,本人菜鸟,请大牛帮忙

解决方案 »

  1.   

    setString(parameterIndex1, x);因为这个方法不是static的
      

  2.   

    我知道可以通过创建这个非静态类的对象,然后就可以调用对象的方法,因为创建对象涉及很多问题,我不想使用这个方法,我首先要搞懂,为什么这个myStatement成了静态的类了呢?
      

  3.   

    楼主看看有没有抄错,应该是Cannot make a static reference to a none static methodPreparedStatement.setString(parameterIndex1, x);是静态方法的访问方法非静态方法一定要创建实例
      

  4.   

    哪个信息告诉你你的类是static class
      

  5.   


    //因为setString方法是非静态的,所以你首先得有个这个PreparedStatement 的实例~用以下方式可以得到!
     public void mySetString(int parameterIndex1,String x) throws SQLException{
     Connection conn = null;//这里你自己写你的连接代码~我这是伪代码~
     PreparedStatement p = conn.prepareStatement("select * form tablename where name=?");
     p.setString(parameterIndex1, x);   
     } 
      

  6.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【blueskyfly119】截止到2008-06-27 20:28:01的历史汇总数据(不包括此帖):
    发帖数:0                  发帖分:0                  
    结贴数:0                  结贴分:0                  
    未结数:0                  未结分:0                  
    结贴率:-------------------结分率:-------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html