|
Based on another day of thinking, I will talk about my current method: 1. I built a Listener to set jndi
public void contextInitialized (ServletContextEvent sce)
{
ServletContext application = sce.getServletContext ();
Context env = null;
/ **
* Get the JNDI and set pool to a atrribute
* Which we can use it in everywhere.
* /
try
{
env = (Context) new InitialContext (). lookup ("java: comp / env");
ds = (DataSource) env.lookup ("jdbc / oracle / message_project");
if (ds == null)
{
application.log ("Can not find jdbc / oracle / message_project JNDI");
}
}
catch (NamingException ne)
{
application.log ("Can not get jdbc / oracle / message_project JNDI");
}
application.setAttribute ("ds", ds);
}
2, and then configure the database connection pool in tomcat5.0
<!-Here's what I added->
<Resource name = "jdbc / oracle / message_project"
auth = "Container"
type = "javax.sql.DataSource" />
<ResourceParams name = "jdbc / oracle / message_project">
<parameter>
<name> factory </ name>
<value> org.apache.commons.dbcp.BasicDataSourceFactory </ value>
</ parameter>
<!-Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
->
<parameter>
<name> maxActive </ name>
<value> 100 </ value>
</ parameter>
<!-Maximum number of idle dB connections to retain in pool.
Set to -1 for no limit. See also the DBCP documentation on this
and the minEvictableIdleTimeMillis configuration parameter.
->
<parameter>
<name> maxIdle </ name>
<value> 30 </ value>
</ parameter>
<!-Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
->
<parameter>
<name> maxWait </ name>
<value> 10000 </ value>
</ parameter>
<!-MySQL dB username and password for dB connections->
<parameter>
<name> username </ name>
<value> System </ value>
</ parameter>
<parameter>
<name> password </ name>
<value> sql </ value>
</ parameter>
<!-Class name for the old mm.mysql JDBC driver-uncomment this entry and comment next
if you want to use this driver-we recommend using Connector / J though
<parameter>
<name> driverClassName </ name>
<value> org.gjt.mm.mysql.Driver </ value>
</ parameter>
->
<!-Class name for the official MySQL Connector / J driver->
<parameter>
<name> driverClassName </ name>
<value> oracle.jdbc.driver.OracleDriver </ value>
</ parameter>
<!-The JDBC connection url for connecting to your MySQL dB.
The autoReconnect = true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
->
<parameter>
<name> url </ name>
<value> jdbc: oracle: thin: @localhost: 1521: admin06 </ value>
</ parameter>
</ ResourceParams>
<!-I added the above->
Problems: 1. I do n’t know if it ’s right or not 2. (I use eclipse + myeclipse) I ca n’t find the database mapping in myeclipse ) Why can't I find it with jndi, of course I know it but I don't know. So I hope you have no pity for your advice. I have been waiting online for a day and a night. . |
|