重起一下weblogic吧
看你的配置没什么问题记得把oracle jdbc的包放到启动路径里
看你的配置没什么问题记得把oracle jdbc的包放到启动路径里
解决方案 »
- 马士兵学JAVA系列教程
- 对接口(webservice,view)提供一种通用的解决方案
- windows media services 启动不了
- Oracle里有没有类似这种的触发器?
- tomcat问题, URIEncoding要如何设置? 高分求解
- JSP 与ASP.NET接合
- tomcat内存溢出,急啊!!!!!!!!!
- jvm不允许我new一个对象
- 求助:如何在xml文件中查询数据
- 有人用Groovy,Scala和Clojure这三种语言吗?他们的前景怎么样?
- 下面的狂简单的语句,就是不对,帮我看看吧!UP有分~~
- JBuilder编译的class,用java 命令行怎么不能运行??UP有分~~~
配置:
1、进入console
2、选择:mydomain-->Services-->JDBC-->Connection Pools-->Configure a new JDBC Connection Pool...
出现connection pool的Configuration页面
Name: My Connection Pool (可任意给出名称)
URL: jdbc:oracle:thin:@192.168.10.240:1521:orcl (这里使用Oracle的thin方式,
只要把URL中的"192.168.10.240"替换成你所使用的数据库服务器地址即可)
Driver Classname: oracle.jdbc.driver.OracleDriver
Properties(key=value): user=user
ACLName: 可不填
Password: pwd点create按钮3、在上个页面中,选择Connections,
Initial Capacity: 2 //初始连接数
Maximum Capacity: 10 //最大连接数
Capacity Increment: 2 //连接池增长步长
Login Delay Seconds: 1 seconds
Refresh Period: 10 minutes
4、选择Testing
Test Table Name: tab (随便填入一个当前表空间中的表名,注意:必填!)
√ Test Reserved Connections
√ Test Released Connections (以上两个checkbox必选)
点apply按钮5、选择:mydomain-->Services-->JDBC-->Data Sources-->Configure a new JDBC Data Source...
Name: My Data Source (自己给定名称)
JNDI Name: mypool (自己给定名称,这是在JNDI中注册的名称,以后创建连接时要用到)
Pool Name: My Connection Pool (这里填入第三步中填入的Name)6、重新启动weblogic
7、选择mydomain-->Services-->JDBC-->Connection Pools-->My Connection Pool-->Target
chosen:myserver
点apply按钮
8、选择:mydomain-->Services-->JDBC-->Data Sources-->My Data Source-->Target
chosen:myserver
点apply按钮
使用例程如下:<%
/**
* testConn.jsp
* weblogic下用获得数据库连接的范例代码
* 最新修改日期:2003-6-4
*/
%><%@ page contentType = "text/html;charset=GBK" %>
<%@ page import="java.sql.*" %>
<%
out.println("Testing my connection pool...<BR>"); // The JDBC Connection object
Connection conn = null; // The JDBC statement object
Statement stmt = null; // The JDBC ResultSet object
ResultSet rs = null;
try
{
//获得连接,其中:"mypool"是本范例使用的Data Source注册在weblogic中的JNDI名称
//注意:jdk1.3.1中并没有javax.sql包,到j2sdkee1.3或者jdk1.4中可以找到
javax.naming.Context ctx = new javax.naming.InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("mypool");
conn = ds.getConnection();
// Create a statement object that we can execute queries with
stmt = conn.createStatement() ; String query1 = "SELECT SYSDATE FROM DUAL";
rs = stmt.executeQuery(query1);
if (rs.next())
{
out.println("OK!");
}
}
catch (Exception ex)
{
// Send the error back to the client
out.println("Exception:" + ex.getMessage());
}
finally
{
try
{
if(rs != null)
{
rs.close();
}
}
catch(Exception ex) {}
try
{
if (stmt != null)
{
stmt.close();
}
}
catch(Exception ex) {}
try
{
if (conn != null)
{
conn.close();
}
}
catch (Exception ex)
{
// Ignore any errors here
}
}
%>完成以上工作后,确定在weblogic上配置的Data Source是可用的,就可以考虑将获得数据库连接的
过程封装起来,如下例所示:package MyBeans;public class MyConn
{
javax.naming.Context ctx = null;
//初始化
public MyConn()
throws Exception
{
ctx = new javax.naming.InitialContext();
} //获得连接
public java.sql.Connection getConn(String JndiName)
throws java.sql.SQLException,Exception
{
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup(JndiName);
java.sql.Connection Conn = ds.getConnection(); return Conn;
} //关闭连接
//注意,在使用完Connection对象之后,必须在程序中显式地调用此方法
public void close(java.sql.Connection conn)
throws java.sql.SQLException,Exception
{
if (conn != null)
{
conn.close();
}
}
}
调用的例子如下:
<%
/**
* testMyConn.jsp
* 测试MyConn
* 最新修改日期:2003-6-4
*/
%><%@ page contentType = "text/html;charset=GBK" %>
<jsp:useBean id="mconn" scope="page" class="MyBeans.MyConn" />
<%@ page import="java.sql.*" %>
<%
out.println("Testing MyConn...<BR>"); // The JDBC Connection object
java.sql.Connection con = null; // The JDBC statement object
java.sql.Statement stmt = null; // The JDBC ResultSet object
java.sql.ResultSet rs = null; try
{
//获得连接,其中:"mypool"是本范例使用的Data Source注册在weblogic中的JNDI名称
con = mconn.getConn("mypool"); // Create a statement object that we can execute queries with
stmt = con.createStatement() ; String query1 = "SELECT SYSDATE FROM DUAL";
rs = stmt.executeQuery(query1);
if (rs.next())
{
out.println("ok!");
}
}
catch (Exception ex)
{
// Send the error back to the client
out.println("SQLException:" + ex.getMessage());
}
finally
{
try
{
if(rs != null)
{
rs.close();
}
}
catch(Exception ex) {}
try
{
if (stmt != null)
{
stmt.close();
}
}
catch(Exception ex) {}
try
{
if (conn != null)
{
//显式关闭连接
mconn.close(conn);
}
}
catch (Exception ex)
{
// Ignore any errors here
}
}
%>
没有配Testing一项就去设target了