具体点...
出错信息
代码...
配置信息 ------------------------------------------------------
我们还年轻牛奶会有的奶牛也会有的
可天天在 csdn 混这些会有吗 ??
出错信息
代码...
配置信息 ------------------------------------------------------
我们还年轻牛奶会有的奶牛也会有的
可天天在 csdn 混这些会有吗 ??
解决方案 »
- 项目开发时,数据库表之间的关系有必要在数据库里建立吗?
- criteria
- hibernate有关query接口的一个问题
- jsp放在web-inf里应该怎么访问?
- 给我介绍一本学JDBC数据库的好书,谢谢!
- 初学struts的问题。。。
- 一个比较简单的jdbc问题,大家帮帮我
- [WEBLOGIC8.1]如何用命令重新启动一个WEB项目
- tomcat老是崩溃,请教高手是怎么回事?
- java.sql.SQLException: Field 'xxx' doesn't have a default value
- JSP在weblogic7里面应该放在哪?
- RMI java.lang.ClassFormatError:错,着急中!!!
jndi/test1 和 jndi/test2 分别对应不同的库。
private Connection getConnection(int Type)
{
try{
Context ctx=new InitialContext();
switch(Type)
{
case 0:
setJndiName("jdbc/test1");
break;
case 1:
setJndiName("jdbc/test2");
break;
}
DataSource ds=(DataSource)ctx.lookup(jndiName);
return ds.getConnection();
}
catch (Exception e)
{
return null;
}
}这是取得连接,返回也正常,只是在从SessionBean中出来的时候在外面的jsp中抛出异常。
import javax.sql.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;
import java.util.*;
/**
* Bean implementation class for Enterprise Bean: Sample
*/
public class SampleBean implements javax.ejb.SessionBean {
private javax.ejb.SessionContext mySessionCtx;
/**
* getSessionContext
*/
public javax.ejb.SessionContext getSessionContext() {
return mySessionCtx;
}
/**
* setSessionContext
*/
public void setSessionContext(javax.ejb.SessionContext ctx) {
mySessionCtx = ctx;
}
/**
* ejbCreate
*/
public void ejbCreate() throws javax.ejb.CreateException {
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() {
}
private Vector v1 = new Vector();
private Vector v2 = new Vector();
public boolean getList()
{
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Connection con1 = null;
Statement stmt1 = null;
ResultSet rs1 = null;
try
{
con = getConnection1();
String sql = "select * from USERINFO";
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
rs.close();
stmt.close();
con.close();
con1 = getConnection2();
String sql1 = "select * from ATMRCD";
stmt1 = con1.createStatement();
rs1 = stmt1.executeQuery(sql1);
}
catch(Exception e)
{
return false;
}
return true;
}
/**
* 获得数据库连接
*/
private Connection getConnection1() throws Exception
{
//String jndiName = getDBJndiName();
try
{
Context ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("jdbc/test1");
return ds.getConnection();
}
catch(Exception e)
{
throw new Exception("连接数据库失败:"+e.toString());
}
}
private Connection getConnection2() throws Exception
{
//String jndiName = getDBJndiName();
try
{
Context ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("jdbc/test2");
return ds.getConnection();
}
catch(Exception e)
{
throw new Exception("连接数据库失败:"+e.toString());
}
}
}
rs = stmt.executeQuery(sql);
rs.close();
stmt.close();
con.close();看这段测试程序,都已经释放了,不过还是没用。
String sql = "select * from USERINFO";
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
rs.close();
stmt.close();
con.close();
con1 = getConnection2();
String sql1 = "select * from ATMRCD";
stmt1 = con1.createStatement();
rs1 = stmt1.executeQuery(sql1);
这样写也会出错吗?
我在JBoss中配过两个连接池,不过是EJB用一个,JSP页面中有时又用了另一个,没出过错~
你把那个方法的事务属性去掉试试~
一个EJB中要用两个连接:)
* 关闭数据库
*/
public void dbClose() {
try {
rs.close();
db.close();
Logger.info("数据库已关闭"); } catch (Exception ex) {
Logger.error(ex.getMessage(), ex);
} finally {
if (rs != null)
try {
rs.close();
} catch (Exception ex) {
Logger.error(ex.getMessage(), ex);
}
if (db != null) {
try {
db.close();
} catch (Exception ex) {
Logger.error(ex.getMessage(), ex);
}
}
}
}