解决了码上给分?
我写了一个数据库连接类:
连接函数如下,我把他放在WEB-INF/classes/data/目录下
但是我不想让
InputStream in=new FileInputStream("E:/sql.properties");中的
E:/sql.properties写成绝对路径,如写成/WEB-INF/sql.properties
但是在jsp页面调用数据库的时候提示找不到路径,我该怎么写呢??
但是不能写成绝对路径,请大家帮忙
public static synchronized Connection getCon()throws Exception{
try{
Properties props=new Properties();
InputStream in=new FileInputStream("E:/sql.properties");
props.load(in);
in.close();
/**
*加载驱动程序
*/
Class.forName(props.getProperty("connection.driver"));
/**
*获取数据库连接
*/
con =DriverManager.getConnection(
props.getProperty("connection.url"),props);
return con;
}catch (SQLException e){
System.out.println(e.getMessage());
throw e;
}
}