加载properties文件报空指针
public class DB {
private Connection conn = null;
private Properties prop = null;
InputStream info = null; //InputStream 对象 ; //InputStream 对象
public Connection getConnection(){
String driverclass,dburl,user,password;
prop = new Properties(); //构建properties对象
//java.lang.Object.getClass(),将jdbc.properties文件内容赋予输入流对象
info = getClass().getResourceAsStream("conf/jdbc.properties");
try {
prop.load(info); //加载输入流对象内容
driverclass = prop.getProperty("driverclass");
dburl = prop.getProperty("dburl");
user = prop.getProperty("user");
password = prop.getProperty("password");
System.out.println(driverclass+dburl+user+password);
Class.forName(driverclass);//加载驱动
conn=DriverManager.getConnection(dburl,user,password);//创建数据库connection对象
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
错误
信息:
严重: Servlet.service() for servlet AccountServlet threw exception
java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:418)
at java.util.Properties.load0(Properties.java:337)
at java.util.Properties.load(Properties.java:325)
at com.etop.topebus.common.DB.getConnection(DB.java:26)
at com.etop.topebus.dao.AccountDao.accountInfo(AccountDao.java:40)
at com.etop.topebus.control.AccountServlet.doPost(AccountServlet.java:57)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
装好apache2.2.4没有了apache.exe?解决方法