我在WEBLOGIC里面配置好ORACLE的连接池:
然后写了一个类DataSource,然后在其他页面调用出错
Compilation of d:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_newfx_newfx\jsp_servlet\_temp\__test.java failed:
--------------------------------------------------------------------------------
d:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_newfx_newfx\jsp_servlet\_temp\__test.java:176: cannot access scm.DatabaseConn
probably occurred due to an error in /temp/test.jsp line 6:
<jsp:useBean id="DatabaseConn" scope="page" class="scm.DatabaseConn"/>
--------------------------------------------------------------------------------
Full compiler error(s):
d:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_newfx_newfx\jsp_servlet\_temp\__test.java:176: cannot access scm.DatabaseConn
bad class file: d:\bea\user_projects\domains\mydomain\myserver\.wlnotdelete\extract\myserver_newfx_newfx\jarfiles\_wl_cls_gen.jar(scm/DatabaseConn.class)
class file has wrong version 49.0, should be 48.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
scm.DatabaseConn DatabaseConn = null; //[ /temp/test.jsp; Line: 6]
^
1 error
下面是类的源码:
package scm;
import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
//一个用于查找数据源的工具类。
public class DatabaseConn {
public static synchronized Connection getConnection() throws Exception
{
try
{
Context initCtx = new javax.naming.InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)initCtx.lookup("jdbc/bn"); ;
return ds.getConnection();
}
catch(SQLException e)
{
throw e;
}
catch(NamingException e)
{
throw e;
}
}
}
调用页面的代码
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.sql.DataSource"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="java.sql.*"%>
<jsp:useBean id="DatabaseConn" scope="page" class="scm.DatabaseConn"/>
<%
//Connection con=scm.getConn();
//Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
Connection con=DatabaseConn.getConnection();
Statement stmt=con.createStatement();
String sqlStr="select * from body order by lasttime desc";
%>
……………………………………………………
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
import java.util.*;
//import oracle.sql.*;
public class DocMan{
Context ctx=null;
DataSource ds=null;
// SysLog log=null;
//ChangeEncoding ce=null;
//构造函数
public DocMan()
{
//从连接池中获取数据库连接
try{
ctx=new InitialContext();
ds=(DataSource)ctx.lookup("myjndi");
}
catch(NamingException e){
e.printStackTrace();
}
//log=new SysLog();
//ce=new ChangeEncoding();
}
//==================================
<jsp:useBean id="DatabaseConn" scope="page" class="scm.DatabaseConn"/>