run as -> java application
debug as -> java application
debug as -> java application
解决方案 »
- jsp页面如何与本地程序交互
- 服务器端webservice更新后,客户端报java.lang.NoClassDefFoundError
- 关于web工程的执行顺序和xml中的配置以及servlet和ajax的关系?
- 使用jdbcTemplate时如何给sql中有in参数赋值
- 想找一份和java有关的工作!
- 使用最新struts2(2.3.15.2),不能使用DMI动态调用方法
- 是不是ServletContext只能在jsp和servlet中获取 在同一个工程工程中的其他class不能直接的取用?
- tomcat中文问题,大部分没问题,有时候出问题,到底是不是问题?
- 关于strutstest的问题?
- 提问。
- 哪儿有mail.jar,activation.jar,xerces.jar
- 这个问题比较困难,有待高人指点
InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup("java:comp/env/jdbc/test");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
....
执行的时候没问题,但是如果我在javabean里面写同样,就会报错:javax.naming.NoInitialContextException: 我想知道的就是tomcat的InitialContext的properties怎么写
InputStream is =getClass().getResourceAsStream("/db.properties");
Properties dbProps = new Properties();
try {
dbProps.load(is);
} catch (Exception e) {
System.err.println("Can't read the properties file. ");
return;
}
URL =dbProps.getProperty("URL","jdbc:postgresql://127.0.0.1:5432/mydb");
String user = dbProps.getProperty("user", "test");
String password = dbProps.getProperty("password", "test");
String driverClasses = props.getProperty("drivers");
Driver driver =(Driver) Class.forName(driverClasses).newInstance();
Connection con = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement();
........