数据库是INFORMIX的例子:安装jDriver for informix:
1. 下载一个informix4。
2. 解压它到weblogic目录。
3. 设置环境变量。如:CLASSPATH=weblogic/informix4/classes
使用连接池的设置:
weblogic.jdbc.connectionPool.informixPool= url=jdbc:weblogic:informix4, driver=weblogic.jdbc.informix4.Driver, loginDelaySecs=1, initialCapacity=2, maxCapacity=10, capacityIncrement=2, allowShrinking=true, shrinkPeriodMins=15, refreshMinutes=10,props=user=informix;password=informix;server=dbyeeyoo@yeeyoo:8888
weblogic.allow.reserve.weblogic.jdbc.connectionPool.informixPool=everyone
weblogic.allow.reset.weblogic.jdbc.connectionPool.informixPool=everyone
weblogic.allow.shrink.weblogic.jdbc.connectionPool.informixPool=everyone
说明:
driver::JDBC驱动程序包的完整目录。
loginDelaysecs:两次连接的时间间隔。
initialCapacity:启动WebLogic时系统建立的连接数。
maxCapacity:最大的连接数。
capacityIncrement:系统每次增加的连接数。
AllowShrinking:允许当请求减少时,连接数量也减少。
shrinkPeriodMins:连接数量减少的时间。
props:与数据库连接的属性。如:登录名,密码,数据库名。
使用:
首先加载连接池的驱动程序,并且用它建立一个Driver类的实例。驱动程序的包是:weblogic.jdbc.pool.Driver。
然后用java.sql.Driver.connect方法建立与informixPool连接池的连接。其返回只是一个Connection 对象。
接着用Connection.CereateStatement()方法建立一个Statement对象。
如果要操作数据集,可以用ResultSet对象。
最后关闭Statement对象和Connection 对象。程序片断:
//建立一个连接
try{
Connection conn=null;
Statement stmt1=null;
Driver myDriver=(Driver) Class.forName("weblogic.jdbc.pool.Driver").newInstance();
conn=myDriver.connect("jdbc:weblogic:pool:informixPool",null);
stmt1=conn.createStatement();
}
catch(Exception e){
out.println(e+"err one");
}
try{
String sql1="select * from cuinformation where sl_num=''"+slnum+"''";
ResultSet rs=stmt.executeQuery(sql1);
while (rs.next()){
customeID=rs.getInt("cu_customeID");
String blgnum = rs.getString("blg_num");
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e){
out.println(e+"err two");
}
1. 下载一个informix4。
2. 解压它到weblogic目录。
3. 设置环境变量。如:CLASSPATH=weblogic/informix4/classes
使用连接池的设置:
weblogic.jdbc.connectionPool.informixPool= url=jdbc:weblogic:informix4, driver=weblogic.jdbc.informix4.Driver, loginDelaySecs=1, initialCapacity=2, maxCapacity=10, capacityIncrement=2, allowShrinking=true, shrinkPeriodMins=15, refreshMinutes=10,props=user=informix;password=informix;server=dbyeeyoo@yeeyoo:8888
weblogic.allow.reserve.weblogic.jdbc.connectionPool.informixPool=everyone
weblogic.allow.reset.weblogic.jdbc.connectionPool.informixPool=everyone
weblogic.allow.shrink.weblogic.jdbc.connectionPool.informixPool=everyone
说明:
driver::JDBC驱动程序包的完整目录。
loginDelaysecs:两次连接的时间间隔。
initialCapacity:启动WebLogic时系统建立的连接数。
maxCapacity:最大的连接数。
capacityIncrement:系统每次增加的连接数。
AllowShrinking:允许当请求减少时,连接数量也减少。
shrinkPeriodMins:连接数量减少的时间。
props:与数据库连接的属性。如:登录名,密码,数据库名。
使用:
首先加载连接池的驱动程序,并且用它建立一个Driver类的实例。驱动程序的包是:weblogic.jdbc.pool.Driver。
然后用java.sql.Driver.connect方法建立与informixPool连接池的连接。其返回只是一个Connection 对象。
接着用Connection.CereateStatement()方法建立一个Statement对象。
如果要操作数据集,可以用ResultSet对象。
最后关闭Statement对象和Connection 对象。程序片断:
//建立一个连接
try{
Connection conn=null;
Statement stmt1=null;
Driver myDriver=(Driver) Class.forName("weblogic.jdbc.pool.Driver").newInstance();
conn=myDriver.connect("jdbc:weblogic:pool:informixPool",null);
stmt1=conn.createStatement();
}
catch(Exception e){
out.println(e+"err one");
}
try{
String sql1="select * from cuinformation where sl_num=''"+slnum+"''";
ResultSet rs=stmt.executeQuery(sql1);
while (rs.next()){
customeID=rs.getInt("cu_customeID");
String blgnum = rs.getString("blg_num");
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e){
out.println(e+"err two");
}
url=jdbc:mysql://localhost/zjws?user=zjxyz,\
driver=org.gjt.mm.mysql.Driver,\
loginDelaySecs=1,\
initialCapacity=4,\
maxCapacity=10,\
capacityIncrement=2,\
allowShrinking=true,\
shrinkPeriodMins=15,\
refreshMinutes=10,\
allow=guest,\
props=user=zjxyz;password=xyz;server=zjxyz 把mysql 的JDBC驱动放在 /weblogic/myserver/serverclasses/ 目录下
mysql一定要比weblogic先启动,因为weblogic在启动时要创建POOL。
mysqlpool.java
--------------------------------------------------------------------------------------------------
import java.io.*;
import java.sql.*;
import weblogic.db.jdbc.*;
import java.util.Properties;
import javax.servlet.*;
import javax.servlet.http.*;
public class mysqlpool extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException
{
res.setContentType("text/html"); PrintWriter out = res.getWriter();
out.println("<html><head><title>Hello World!</title></head>");
out.println("<body><h1>TEST Weblogic Pool!</h1><pre>");
Connection Conn = null; try {
//=================================================================================
Properties props =new Properties();
props.setProperty("user", "system");
props.setProperty("password", "zjxyzken"); Driver myDriver =
(Driver) Class.forName("weblogic.jdbc.pool.Driver").newInstance(); Conn = myDriver.connect("jdbc:weblogic:pool:mysqlPool1",props);
//================================================================================= //
Statement Stmt = Conn.createStatement();
ResultSet RS = Stmt.executeQuery("SELECT * from users"); while (RS.next()) { out.println(RS.getString("userid")+"\t"
+RS.getString("passwd")
+"\t"+RS.getString("name"));
} RS.close();
Stmt.close();
Conn.close(); }catch (Exception E) {
System.err.println("Unable to load driver.");
E.printStackTrace();
}
out.println("</pre></body></html>");
}
}
通过console 建立了SQLPool 但 weblogic启动时报错说 ejb 的jar包weblogic.ejb20.cmp.rdbms.RDBMSException: Unexpected failure while accessing tabl
e 'dbo.Users': java.sql.SQLException: Connection Pool SQLPool does not exist. j
ava.sql.SQLException: Connection Pool SQLPool does not exist.
pools name == MyConnPool
url==jdbc:weblogic:informix4
driverclassname==weblogic.jdbc.informix4.Driver
Properties
(key=value):
db=dbname
port=port
user=username
password=pwd
server=IP
然后在Data Sources中配置
JNDI Name: MyDS
Pool Name: MyConnPool(前面配置的pool name)以上两步都要求在target中选择你的server!