日期:2014-05-20  浏览次数:21177 次

怪异的错误
错误 java.lang.NullPointerException
  vote.util.SimpleDBUtil.prepareStatement(SimpleDBUtil.java:45)

代码
public static PreparedStatement prepareStatement(Connection conn,String sql){

PreparedStatement ps=null;
try {
ps=conn.prepareStatement(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ps;
}

求大虾们指教

------解决方案--------------------
你这里很可能是conn这个参数也是为null,你换代码为
Java code

public static PreparedStatement prepareStatement(Connection conn,String sql){
if(conn==null)
   System.out.println("--------------conn==null");
  
PreparedStatement ps=null;
try {
ps=conn.prepareStatement(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ps;
}

------解决方案--------------------
Connection=null