在tomcat中配置了数据源
在jsp页面可以正常获取,但现在想写一个数据源管理连接的类,却总是获取不到数据源
测试时总是抛出Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial是不是在tomcat中配置的数据源只能在jsp中使用
如果想在普通类中使用,该如何配置
在jsp页面可以正常获取,但现在想写一个数据源管理连接的类,却总是获取不到数据源
测试时总是抛出Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial是不是在tomcat中配置的数据源只能在jsp中使用
如果想在普通类中使用,该如何配置
解决方案 »
- Android or Web This is question
- 求富文本编辑器
- 连接ACCESS 用getRow() 得到返回结果为 0 怎么回事?
- (100分新手求教)把图片保存到Oracle的BLOB字段中的问题
- 关于JS 子窗口控制父窗口 布局~
- jboss服务器报错,如何解决
- 使用 org.apache.commons.net.tftp 的问题,文件的最后一部分不能传输
- Struts下使用type="stream"配置action,文件下载时报错getOutputStream() has already been called
- 请问大家,现在都用什么来配置jsp环境的呀?
- 我用JSP做留言本,在插入记录时有些问题
- jsp页面中无法得到数据库中的值
- 页面上的下拉框问题
* Get a connection from pool
*
* @return a Connection
*/
public static Connection getConnection() {
Connection conn = null;
try{
if(initCtx == null){
initCtx = new InitialContext();
}
if(ds == null){
ds = (DataSource)initCtx.lookup(resource);
}
try{
conn = ds.getConnection();
}catch(SQLException e1){
// erro = e1.toString();
}
}catch(NamingException e){
}
return conn;
} /**
* Look up the DataSource
*
* @return the DataSource
*/
public static DataSource getDataSource() {
try{
if(initCtx == null){
initCtx = new InitialContext();
}
if(ds == null){
ds = (DataSource)initCtx.lookup(resource);
}
}catch(NamingException e){
}
return ds;
}
你参考一下吧..我一直都是用这个
一般只需要修改jdbc/jhll这儿就可以了..如JDBC/XXXX