MySQL connection pooling guidelines
Dear tribe,
Although using autoReconnect=true in my pool definition, I keep running out of connections...
This morning changed to autoReconnectForPools=true flag (along with autoReconnect) and upgraded to Connector/J 3.0.11.
While I'm waiting to see if this will work out, can someone please point to some guidelines on setting up connection pools specifically for MySQL and AppServer7 or post a working configuration (jar versions, web.xml fragment etc)?
Thanks,
Manos
My initial configuration was exactly that but was failing to connect after leaving the applicatin running for 8 hours. I then added autoReconnect=true and autoReconnectForPools=true. But after leaving the application running without any requests to it, this morning i tried to load a page and got closed connection errors again...
javax.servlet.ServletException: Could not execute query
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:478)
at jasper.monthly_jsp._jspService(_monthly_jsp.java:524)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.ias.web.jsp.JspServlet$JspServletWrapper.service(JspServlet.java:552)
at com.iplanet.ias.web.jsp.JspServlet.serviceJspFile(JspServlet.java:368)
at com.iplanet.ias.web.jsp.JspServlet.service(JspServlet.java:287)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at gr.netsmart.manos2.jstats.filters.WebStatisticsKeeper.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:265)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:157)
at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
Root Cause
net.sf.hibernate.JDBCException: Could not execute query
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1478)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at jasper.monthly_jsp._jspService(_monthly_jsp.java:158)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.ias.web.jsp.JspServlet$JspServletWrapper.service(JspServlet.java:552)
at com.iplanet.ias.web.jsp.JspServlet.serviceJspFile(JspServlet.java:368)
at com.iplanet.ias.web.jsp.JspServlet.service(JspServlet.java:287)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at gr.netsmart.manos2.jstats.filters.WebStatisticsKeeper.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:265)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:157)
at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
Caused by: java.sql.SQLException: No operations allowed after connection closed.
Connection was closed due to the following exception:
** BEGIN NESTED EXCEPTION **
java.sql.SQLException
MESSAGE: Communication link failure: java.io.EOFException, underlying cause: null
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1319)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1463)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1854)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1109)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1203)
at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1164)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2087)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2049)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2030)
at com.mysql.jdbc.Connection.rollbackNoChecks(Connection.java:3004)
at com.mysql.jdbc.Connection.rollback(Connection.java:1458)
at com.sun.enterprise.resource.JdbcXAConnection$JdbcConnection.getCurrentConnection(JdbcXAConnection.java:640)
at com.sun.enterprise.resource.JdbcXAConnection$JdbcConnection.prepareStatement(JdbcXAConnection.java:378)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:228)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:61)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:703)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:184)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
at net.sf.hibernate.loader.Loader.doList(Loader.java:949)
at net.sf.hibernate.loader.Loader.list(Loader.java:940)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:833)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1475)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at jasper.monthly_jsp._jspService(_monthly_jsp.java:158)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.ias.web.jsp.JspServlet$JspServletWrapper.service(JspServlet.java:552)
at com.iplanet.ias.web.jsp.JspServlet.serviceJspFile(JspServlet.java:368)
at com.iplanet.ias.web.jsp.JspServlet.service(JspServlet.java:287)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at gr.netsmart.manos2.jstats.filters.WebStatisticsKeeper.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:265)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:157)
at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
** END NESTED EXCEPTION **
STACKTRACE:
java.sql.SQLException: Communication link failure: java.io.EOFException, underlying cause: null
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1319)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1463)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1854)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1109)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1203)
at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1164)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2087)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2049)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2030)
at com.mysql.jdbc.Connection.rollbackNoChecks(Connection.java:3004)
at com.mysql.jdbc.Connection.rollback(Connection.java:1458)
at com.sun.enterprise.resource.JdbcXAConnection$JdbcConnection.getCurrentConnection(JdbcXAConnection.java:640)
at com.sun.enterprise.resource.JdbcXAConnection$JdbcConnection.prepareStatement(JdbcXAConnection.java:378)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:228)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:61)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:703)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:184)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
at net.sf.hibernate.loader.Loader.doList(Loader.java:949)
at net.sf.hibernate.loader.Loader.list(Loader.java:940)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:833)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1475)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at jasper.monthly_jsp._jspService(_monthly_jsp.java:158)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.ias.web.jsp.JspServlet$JspServletWrapper.service(JspServlet.java:552)
at com.iplanet.ias.web.jsp.JspServlet.serviceJspFile(JspServlet.java:368)
at com.iplanet.ias.web.jsp.JspServlet.service(JspServlet.java:287)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at gr.netsmart.manos2.jstats.filters.WebStatisticsKeeper.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:265)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:157)
at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
** END NESTED EXCEPTION **
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1638)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1854)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1109)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1203)
at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1164)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2087)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2049)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2030)
at com.mysql.jdbc.Connection.rollbackNoChecks(Connection.java:3004)
at com.mysql.jdbc.Connection.rollback(Connection.java:1458)
at com.sun.enterprise.resource.JdbcXAConnection$JdbcConnection.getCurrentConnection(JdbcXAConnection.java:640)
at com.sun.enterprise.resource.JdbcXAConnection$JdbcConnection.prepareStatement(JdbcXAConnection.java:378)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:228)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:61)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:703)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:184)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
at net.sf.hibernate.loader.Loader.doList(Loader.java:949)
at net.sf.hibernate.loader.Loader.list(Loader.java:940)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:833)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1475)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at jasper.monthly_jsp._jspService(_monthly_jsp.java:158)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.ias.web.jsp.JspServlet$JspServletWrapper.service(JspServlet.java:552)
at com.iplanet.ias.web.jsp.JspServlet.serviceJspFile(JspServlet.java:368)
at com.iplanet.ias.web.jsp.JspServlet.service(JspServlet.java:287)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at gr.netsmart.manos2.jstats.filters.WebStatisticsKeeper.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:98)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:265)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:157)
at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
** END NESTED EXCEPTION **
at com.mysql.jdbc.Connection.checkClosed(Connection.java:2225)
at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:501)
at com.sun.enterprise.resource.JdbcXAConnection$JdbcConnection.getCurrentConnection(JdbcXAConnection.java:641)
at com.sun.enterprise.resource.JdbcXAConnection$JdbcConnection.prepareStatement(JdbcXAConnection.java:378)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:228)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:61)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:703)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:184)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
at net.sf.hibernate.loader.Loader.doList(Loader.java:949)
at net.sf.hibernate.loader.Loader.list(Loader.java:940)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:833)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1475)
... 27 more
Similar Messages
-
Hello,
I am trying to create a mysql connection pool using the admin console. The mysql JDBC driver is located in <install_dir>/domains/domain1/lib/ext.
For Datasource Classname I use com.mysql.jdbc.jdbc2.optional.MysqlDataSource
A ping results in:
Operation 'pingConnectionPool' failed in 'resources' Config Mbean. Target exception message: Connection could not be allocated because: null, message from server: "Host 'localhost.localdomain' is not allowed to connect to this MySQL server"
When changing the URL property to localhost a ping results in:
Operation 'pingConnectionPool' failed in 'resources' Config Mbean. Target exception message: Connection object cannot be null
Any ideas about what goes wrong?
Thanks...I did a simple php test:
<?php
mysql_connect("localhost.localdomain", "user", "pass") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
This results in:
Warning: mysql_connect(): Host 'localhost.localdomain' is not allowed to connect to this MySQL server in /var/www/mathesis/mambo/mysql.php on line 2
Host 'localhost.localdomain' is not allowed to connect to this MySQL server
<?php
mysql_connect("localhost", "user", "pass") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
results in: Connected to MySQL
So I see two possible solutions:
1) Make the appserver use localhost instead of localhost.localdomain (specifying localhost as property doesn't work!).
2) Make MySQL accept localhost.localdomain connections.
For both possible solutions I'm searching for answers...
-Michael -
MySQL connection pooling (tomcat) problem
Hi all i just started learning servlets and i want to make a program in order to understand database connection pooling in tomcat.My problem is that when i run the servlet i created i get this error :
java.lang.NullPointerException org.DB.TestDB2.doGet(TestDB2.java:105) javax.servlet.http.HttpServlet.service(HttpServlet.java:690) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
And that from tomcat log from netbeans :
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
.I configured tomcat server.xml file like this :
<Context path="/DBTest" docBase="DBTest" debug="5" reloadable="true" crossContext="true"> <Resource name="jdbc/phonebook_db" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="*******" password="********" removeAbandoned="true" removeAbandonedTimeout="120" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test_phonebook_db?autoReconnect=true"/> </Context>
This is the resource reference i have in my web app web.xml file :
<resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/phonebook_db</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
And this is my servlet class :
package org.DB; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*; import javax.naming.*; import javax.sql.*; public class TestDB2 extends HttpServlet { private Connection conn ; private Statement stat ; private ResultSet rs ; private int counter; private Object rsValue; public void init() { try { InitialContext ctx = new InitialContext(); DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/phonebook_db"); conn = ds.getConnection(); } catch(Exception e) { e.printStackTrace(); } } public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { try { stat = conn.createStatement(); rs = stat.executeQuery("SELECT * FROM phones_table"); } catch (SQLException sqle) { sqle.printStackTrace(); } response.setContentType("text/html; charset=utf-8"); PrintWriter out = response.getWriter(); String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">\n"; out.println(docType +"<HTML>\n" + "<HEAD><TITLE>PhoneBook entries</TITLE></HEAD>\n"); counter = 0; try { while (rs.next()) { out.println("<h4>Entry no. " + (++counter) + "</h4>"); out.println("<table width=\"75%\" border=\"1\">"); out.println("<tr>\n"+ "<td width=\21%\"><b>LastName:</b></td>\n"+ "<td width=\"79%\">"); out.println((((rsValue = rs.getObject("LASTNAME"))==null || rs.wasNull())? "":(rsValue.toString()))); out.println("</td>\n</tr>\n" + "<tr>\n"+ "<td width=\21%\"><b>FirstName:</b></td>\n"+ "<td width=\"79%\">"); out.println((((rsValue = rs.getObject("FIRSTNAME"))==null || rs.wasNull())? "":(rsValue.toString()))); out.println("</td>\n"+ "</tr>\n"+ "<td width=\21%\"><b>Phone:</b></td>\n"+ "<td width=\"79%\">"); out.println((((rsValue = rs.getObject("PHONE"))==null || rs.wasNull())? "":(rsValue.toString()))); out.println("</td>\n" + "</tr>\n" + "</table>\n"+ "<br>\n<br>"); } } catch (SQLException sqle) { sqle.printStackTrace(); } out.println("</body>\n"+ "</html>"); } public void destroy() { try { rs.close(); stat.close(); conn.close(); } catch (SQLException sqle) { sqle.printStackTrace(); } } }{code} Any suggestions?Thank you for your answer.Yes my servlet class is something more worse than horrible(i don't use the database connection correct i don't use the MVC pattern i use out.println() ) but i just tried to take a ready example and try to understand .So i write this servlet myself as a starting point :
package org.DB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.sql.*;
public class DBServlet extends HttpServlet {
private Connection conn ;
private Statement stat ;
private ResultSet rs ;
private int counter;
String driver = "com.mysql.jdbc.Driver";
String dbURL = "jdbc:mysql://localhost:3306/phonebookdb?user=**********&password=************";
@Override
public void init() {
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(dbURL);
}catch(Exception e) {
e.printStackTrace();
System.err.print("Unable to make connection ");
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet DBServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet DBServlet at " + request.getContextPath () + "</h1>");
out.println("<br /><br /><br />");
if(conn!=null)
out.println("conn object : "+conn);
out.println("</body>");
out.println("</html>");
} catch(Exception sq) {
System.out.println("Exception" + sq.getMessage());
out.close();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
public void destroy() {
try {
conn.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
@Override
public String getServletInfo() {
return "A Simple Servlet";
}And it work for now.
Edited by: pavlos555 on Oct 21, 2008 10:21 AM -
MySQL - Connection Pooling - Driver?
Hi there!
I am looking for a JDBC 2.0 compatible driver to use with MySQL. I would like to use connection pooling in a webapplication (JSP:s and Servlets) but I have just found out that the driver I usually use mmmysql do not support connection pooling. Hence, my question: Where can I find a driver to use with MySQL with support for Connection Pooling?
bwhave you tried resin..
http://www.caucho.com/projects/jdbc-mysql/index.xtp
i haven't checked it yet but it could be an option
i'm currently using mmmysql driver also...I tried that driver and when I had more than one statement open at the same time, it gave me garbage results and then threw an exception. So I'm using the mmmysql driver too. -
Error using mySQL connection Pool
I see the following error when my application uses the connection pool - can anyone explain this ?
INFO: CORE3282: stdout: =======================>ERROR :com.sun.enterprise.repository.J2EEResourceException
WARNING: CORE3283: stderr: at com.sun.enterprise.resource.IASNonSharedResourcePool.initPool(IASNonSharedResourcePool.java:416)
WARNING: CORE3283: stderr: at com.sun.enterprise.resource.IASNonSharedResourcePool.internalGetResource(IASNonSharedResourcePool.java:625)
WARNING: CORE3283: stderr: at com.sun.enterprise.resource.IASNonSharedResourcePool.getResource(IASNonSharedResourcePool.java:520)
INFO: CORE3282: stdout: java.lang.NoSuchMethodException: setdataSourceNameHi,
You have used dataSourceName property while creating a connection pool.This property is not required to be set while creating a connection pool for MySql
Use the following properties:
<property name="serverName" value="<name of server>"
<property name="port" value="<port number>"
<property name="DatabaseName" value="<your db name>"
<property name="User" value="<user name>"
<property name="Password" value="<passwd>"
Get back in case of any issues -
Our application uses castor and MySQL. When running in WebLogic, what is the best (portability is key) way to provide a connection pool to my application?
Thanks in advance!
George Redens
Sr. Developer
CertAlert Software, IncDo you write the code that obtains your JDBC
connections, or is it embedded in Castor?
If you can write the code that obtains your
jdbc connections, then the standard pool
documentation is what you should follow.
If you do not have direct access to the
code creating your JDBC connections,
tell us how you specify them, and maybe you
can use our pools, and maybe not.
Joe -
Toplink Mysql Connection pool issues
I am frequently seeing threads in wait state on toplink connection pool, I have given the stack trace below, anyone has any ideas as to what is happening? is it
related to connection timeout? or other causes...
"http-0.0.0.0-8080-2" id=397 idx=0x620 tid=5344 prio=5 alive, in native, waiting
, daemon
-- Waiting for notification on: oracle/toplink/threetier/ConnectionPool@0x00
F181D8[fat lock]
at jrockit/vm/Threads.waitForNotifySignal(JLjava/lang/Object;)Z(Native Metho
d)
at java/lang/Object.wait(J)V(Native Method)[optimized]
at java/lang/Object.wait(Object.java:474)
at oracle/toplink/threetier/ConnectionPool.acquireConnection(ConnectionPool.
java:65)
^-- Lock released while waiting: oracle/toplink/threetier/ConnectionPool@0x0
0F181D8[fat lock]
at oracle/toplink/threetier/ServerSession.allocateReadConnection(ServerSessi
on.java:412)
at oracle/toplink/threetier/ServerSession.executeCall(ServerSession.java:443
at oracle/toplink/internal/queryframework/DatasourceCallQueryMechanism.execu
teCall(DatasourceCallQueryMechanism.java:193)
at oracle/toplink/internal/queryframework/DatasourceCallQueryMechanism.execu
teCall(DatasourceCallQueryMechanism.java:179)
at oracle/toplink/internal/queryframework/DatasourceCallQueryMechanism.execu
teSelectCall(DatasourceCallQueryMechanism.java:250)
at oracle/toplink/internal/queryframework/DatasourceCallQueryMechanism.selec
tAllRows(DatasourceCallQueryMechanism.java:583)
at oracle/toplink/internal/queryframework/ExpressionQueryMechanism.selectAll
RowsFromTable(ExpressionQueryMechanism.java:2483)
at oracle/toplink/internal/queryframework/ExpressionQueryMechanism.selectAll
Rows(ExpressionQueryMechanism.java:2441)
at oracle/toplink/queryframework/ReadAllQuery.executeObjectLevelReadQuery(Re
adAllQuery.java:467)
at oracle/toplink/queryframework/ObjectLevelReadQuery.executeDatabaseQuery(O
bjectLevelReadQuery.java:874)
at oracle/toplink/queryframework/DatabaseQuery.execute(DatabaseQuery.java:67
4)
at oracle/toplink/queryframework/ObjectLevelReadQuery.execute(ObjectLevelRea
dQuery.java:835)
at oracle/toplink/queryframework/ReadAllQuery.execute(ReadAllQuery.java:445)
at oracle/toplink/internal/sessions/AbstractSession.internalExecuteQuery(Abs
tractSession.java:2260)
at oracle/toplink/internal/sessions/AbstractSession.executeQuery(AbstractSes
sion.java:1074)
at oracle/toplink/internal/sessions/AbstractSession.executeQuery(AbstractSes
sion.java:1058)
at oracle/toplink/internal/sessions/AbstractSession.executeQuery(AbstractSes
sion.java:1017)
at com/integral/query/QueryServiceC.executeQuery(QueryServiceC.java:1030)
at com/integral/query/QueryServiceC._find(QueryServiceC.java:525)
at com/integral/query/QueryServiceC._findAll(QueryServiceC.java:123)
at com/integral/query/QueryServiceC.findAll(QueryServiceC.java:83)
at com/integral/query/ejb/QueryServiceC.findAll(QueryServiceC.java:59)Hello,
It looks like you are using a TopLink managed connection pool and do not have enough connections available for the number of threads needing to use one. This results in threads having to wait until one is released from another thread. In the thread shown, it is waiting to get a read connection from the read pool.
TopLink connection pools are described in the docs at:
http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/srvclius002.htm#CHDJAECD
I'd recommend increasing the min/max number of connections to something that is appropriate to handle your peak load based on your applications usage paterns.
Best Regards,
Chris -
MySql connection pooling in Tomcat 4.1
Hi,
Could somebody help me before I go insane ?
I have installed Tomcat 4.1 and MySql and is now trying to follow the example at http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html to set up a pooled connection to the database.
When i try to look up the DataSource :
DataSource ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/lonDB");
I get an error :
DbcpDataSourceFactory: driverClassName is required
cheers
/HHello,
Even though my problem is different, I just appended to this older posting because I am following the same tutorial for setting up a DB Conn pool with MySql.
The problem that I am having is that Tomcat can't find the DBTest class which I copied and compiled from the tutorial.
Where does one have to place their classes for Tomcat 4.1 to see them? In the older version of Tomcat which we use, all we had to was to place the class directory in the CLASSPATH variable on the server, and Tomcat was able to access the classes. We did the same approach for v4.1 but it does not seem to be working.
Any help is appreciated!
Thanks,
Chris -
Replace Quotes, Connection Pooling, and Sun Web Server with MySQL, Oracle
This is code I use to insert data into my MySQL and Oracle databases.
I takes care of quotes and shows use of context, i.e. when you use Sun Web Server's
ConnectionPooling. This code works. Feel free to reply if you have questions on how to set up connection pooling using Sun Web Server 6.1SP - it took quite a long time to learn and I couldn't find much information throughout the web, so I hope this helps...
This is not a question and I am not looking for an answer, but please post comments or suggestions.
dailysun
This is in one class where I have a hashtable containing the
column name / value pairs that I want to enter into my table.
This class simply creates the SQL string from the values in the
hashtable. It then passes that hashtable including the database
name to a class which executes that sql statement (second code
portion).
/* Insert data into sf_parts. Create the column strings from
* the provided hash table. Be sure to parse out hash elements which
* are used for the createTemplate process
StringBuffer values = new StringBuffer();
StringBuffer fields = new StringBuffer();
Enumeration keys = fieldHash.keys();
while(keys.hasMoreElements()){
Object currentKey = keys.nextElement();
String fieldValue = (String) fieldHash.get(currentKey);
if(values.length() >0){
values.append(",");
values.append("'"+fieldValue.replaceAll("'","''")+"'"); // Takes care of quotes and various other special characters!
if(fields.length() >0){
fields.append(",");
fields.append(currentKey);
sql = "INSERT INTO myTable (" + fields.toString() + ") VALUES (" + values.toString() + ");";
String insertResult = caq.getInsertDelete(sql,"myDatabaseName"); // your database name is defined in web.xml and sun-web.xml when you use Sun Web Server's Connection Pooling.
returnValue += "<br><br><b>Rows inserted into table(myTable): </b>" + insertResult + "<br>\n";
And, like I describe above, this method executes the sql statement.
* Takes care of insert, update and delete requests.
* Must have set both dbName as well as the sql String.
* Will return number of rows affected as String.
* @return String Number of rows affected
* @exception SQLException
* @exception Exception
public String getInsertDelete() {
checkData(); // this simply checks if the variables dbName and sql are not empty ;-)
InitialContext initContext = null;
int rv = 0;
try{
// Get connection from configured pool
initContext = new InitialContext();
source = (DataSource) initContext.lookup("java:comp/env/jdbc/" + dbName); // I have this set up in web.xml and sun-web.xml (I use Sun Web Server 6.1SP which does connection pooling for me)
conn = source.getConnection();
if(conn != null){
stmt = conn.createStatement();
rv = stmt.executeUpdate(sql);
}catch (SQLException e){
// do something
}catch (Exception e){
// do something
}finally{
try{
stmt.close();
}catch(Exception e){
// do something
try{
conn.close();
}catch(Exception e){
// do something
try{
initContext.close();
}catch(Exception e){
// do something
return rv+"";
}This is code I use to insert data into my MySQL and
Oracle databases.
I takes care of quotes and shows use of context, i.e.
when you use Sun Web Server's
ConnectionPooling. This code works. Feel free to
reply if you have questions on how to set up
connection pooling using Sun Web Server 6.1SP - it
took quite a long time to learn and I couldn't find
much information throughout the web, so I hope this
helps...
This is not a question and I am not looking for an
answer, but please post comments or suggestions.Using prepared statements would mean that you wouldn't have to worry about quotes.
You should be closing the result set.
You are handling all fields as strings. That won't work with time fields and might not work for numeric fields.
Presumably most of your variables are member variables. They should be local variables because that is the scope of the usage.
You must do something with the exceptions.
Hashtables although convienent mean that problems with usage can only be resolved at run time rather than compile time. -
Has anyone run the connection pooling for mysql & tomcat successfully?
I'm trying to set up connection pooling. I'm following the how-to page at
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
But when i test the DBTest/test.jsp file, tomcat displays an error =
could not load jdbc driver class 'null'(msdos)
i have placed all the required .jar files in the tomcat lib.
below is the cofiguration i did to the server.xml file
<!-- Example Server Configuration File -->
<!-- Note that component elements are nested corresponding to their
parent-child relationships with each other -->
<!-- A "Server" is a singleton element that represents the entire JVM,
which may contain one or more "Service" instances. The Server
listens for a shutdown command on the indicated port.
Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" or "Loggers" at this level.
-->
<Server port="8005" shutdown="SHUTDOWN" debug="0">
<!-- Uncomment these entries to enable JMX MBeans support -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
debug="0"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
debug="0"/>
<!-- Global JNDI resources -->
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved">
</Resource>
<ResourceParams name="UserDatabase">
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" (and therefore the web applications visible
within that Container). Normally, that Container is an "Engine",
but this is not required.
Note: A "Service" is not itself a "Container", so you may not
define subcomponents such as "Valves" or "Loggers" at this level.
-->
<!-- Define the Tomcat Stand-Alone Service -->
<Service name="Tomcat-Standalone">
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Each Connector passes requests on to the
associated "Container" (normally an Engine) for processing.
By default, a non-SSL HTTP/1.1 Connector is established on port 8080.
You can also enable an SSL HTTP/1.1 Connector on port 8443 by
following the instructions below and uncommenting the second Connector
entry. SSL support requires the following steps (see the SSL Config
HOWTO in the Tomcat 4.0 documentation bundle for more detailed
instructions):
* Download and install JSSE 1.0.2 or later, and put the JAR files
into "$JAVA_HOME/jre/lib/ext".
* Execute:
%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)
$JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA (Unix)
with a password value of "changeit" for both the certificate and
the keystore itself.
By default, DNS lookups are enabled when a web application calls
request.getRemoteHost(). This can have an adverse impact on
performance, so you can disable it by setting the
"enableLookups" attribute to "false". When DNS lookups are disabled,
request.getRemoteHost() will return the String version of the
IP address of the remote client.
-->
<!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8081 -->
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
port="8080" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="100" debug="0" connectionTimeout="20000"
useURIValidationHack="false" disableUploadTimeout="true" />
<!-- Note : To disable connection timeouts, set connectionTimeout value
to -1 -->
<!-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
<!--
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
port="8443" minProcessors="5" maxProcessors="75"
enableLookups="true"
acceptCount="100" debug="0" scheme="https" secure="true"
useURIValidationHack="false" disableUploadTimeout="true">
<Factory className="org.apache.coyote.tomcat4.CoyoteServerSocketFactory"
clientAuth="false" protocol="TLS" />
</Connector>
-->
<!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
port="8009" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" connectionTimeout="20000"
useURIValidationHack="false"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>
<!-- Define an AJP 1.3 Connector on port 8009 -->
<!--
<Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
port="8009" minProcessors="5" maxProcessors="75"
acceptCount="10" debug="0"/>
-->
<!-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
<!-- See proxy documentation for more information about using this. -->
<!--
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
port="8082" minProcessors="5" maxProcessors="75"
enableLookups="true" disableUploadTimeout="true"
acceptCount="100" debug="0" connectionTimeout="20000"
proxyPort="80" useURIValidationHack="false" />
-->
<!-- Define a non-SSL legacy HTTP/1.1 Test Connector on port 8083 -->
<!--
<Connector className="org.apache.catalina.connector.http.HttpConnector"
port="8083" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" />
-->
<!-- Define a non-SSL HTTP/1.0 Test Connector on port 8084 -->
<!--
<Connector className="org.apache.catalina.connector.http10.HttpConnector"
port="8084" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" />
-->
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host). -->
<!-- Define the top level container in our container hierarchy -->
<Engine name="Standalone" defaultHost="localhost" debug="0">
<!-- The request dumper valve dumps useful debugging information about
the request headers and cookies that were received, and the response
headers and cookies that were sent, for all requests received by
this instance of Tomcat. If you care only about requests to a
particular virtual host, or a particular application, nest this
element inside the corresponding <Host> or <Context> entry instead.
For a similar mechanism that is portable to all Servlet 2.3
containers, check out the "RequestDumperFilter" Filter in the
example application (the source for this filter may be found in
"$CATALINA_HOME/webapps/examples/WEB-INF/classes/filters").
Request dumping is disabled by default. Uncomment the following
element to enable it. -->
<!--
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
-->
<!-- Global logger unless overridden at lower levels -->
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="catalina_log." suffix=".txt"
timestamp="true"/>
<!-- Because this Realm is here, an instance will be shared globally -->
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
debug="0" resourceName="UserDatabase"/>
<!-- Comment out the old realm but leave here for now in case we
need to go back quickly -->
<!--
<Realm className="org.apache.catalina.realm.MemoryRealm" />
-->
<!-- Replace the above Realm with one of the following to get a Realm
stored in a database and accessed via JDBC -->
<!--
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost/authority"
connectionName="test" connectionPassword="test"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
-->
<!--
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"
connectionName="scott" connectionPassword="tiger"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
-->
<!--
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="sun.jdbc.odbc.JdbcOdbcDriver"
connectionURL="jdbc:odbc:CATALINA"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
-->
<!-- Define the default virtual host -->
<Host name="localhost" debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/my-jsp" docBase="c:\JSP-Files" debug="0"
privileged="true" reloadable="true" />
<Context path="" docBase="c:\Inetpub\wwwroot" debug="0" privileged="true" />
<Context path="/sharon" docBase="C:\Tomcat 4.1\webapps\sharon" debug="0" privileged="true" />
<!-- Normally, users must authenticate themselves to each web app
individually. Uncomment the following entry if you would like
a user to be authenticated the first time they encounter a
resource protected by a security constraint, and then have that
user identity maintained across all web applications contained
in this virtual host. -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn"
debug="0"/>
-->
<!-- Access log processes all requests for this virtual host. By
default, log files are created in the "logs" directory relative to
$CATALINA_HOME. If you wish, you can specify a different
directory with the "directory" attribute. Specify either a relative
(to $CATALINA_HOME) or absolute path to the desired directory.
-->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
-->
<!-- Logger shared by all Contexts related to this virtual host. By
default (when using FileLogger), log files are created in the "logs"
directory relative to $CATALINA_HOME. If you wish, you can specify
a different directory with the "directory" attribute. Specify either a
relative (to $CATALINA_HOME) or absolute path to the desired
directory.-->
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="localhost_log." suffix=".txt"
timestamp="true"/>
<!-- Define properties for each web application. This is only needed
if you want to set non-default properties, or have web application
document roots in places other than the virtual host's appBase
directory. -->
<!-- Tomcat Root Context -->
<!--
<Context path="" docBase="ROOT" debug="0"/>
-->
<!-- Tomcat Examples Context -->
<Context path="/examples" docBase="examples" debug="0"
reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
timestamp="true"/>
<Ejb name="ejb/EmplRecord" type="Entity"
home="com.wombat.empl.EmployeeRecordHome"
remote="com.wombat.empl.EmployeeRecord"/>
<!-- If you wanted the examples app to be able to edit the
user database, you would uncomment the following entry.
Of course, you would want to enable security on the
application as well, so this is not done by default!
The database object could be accessed like this:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
UserDatabase database =
(UserDatabase) envCtx.lookup("userDatabase");
-->
<!--
<ResourceLink name="userDatabase" global="UserDatabase"
type="org.apache.catalina.UserDatabase"/>
-->
<!-- PersistentManager: Uncomment the section below to test Persistent
Sessions.
saveOnRestart: If true, all active sessions will be saved
to the Store when Catalina is shutdown, regardless of
other settings. All Sessions found in the Store will be
loaded on startup. Sessions past their expiration are
ignored in both cases.
maxActiveSessions: If 0 or greater, having too many active
sessions will result in some being swapped out. minIdleSwap
limits this. -1 means unlimited sessions are allowed.
0 means sessions will almost always be swapped out after
use - this will be noticeably slow for your users.
minIdleSwap: Sessions must be idle for at least this long
(in seconds) before they will be swapped out due to
maxActiveSessions. This avoids thrashing when the site is
highly active. -1 or 0 means there is no minimum - sessions
can be swapped out at any time.
maxIdleSwap: Sessions will be swapped out if idle for this
long (in seconds). If minIdleSwap is higher, then it will
override this. This isn't exact: it is checked periodically.
-1 means sessions won't be swapped out for this reason,
although they may be swapped out for maxActiveSessions.
If set to >= 0, guarantees that all sessions found in the
Store will be loaded on startup.
maxIdleBackup: Sessions will be backed up (saved to the Store,
but left in active memory) if idle for this long (in seconds),
and all sessions found in the Store will be loaded on startup.
If set to -1 sessions will not be backed up, 0 means they
should be backed up shortly after being used.
To clear sessions from the Store, set maxActiveSessions, maxIdleSwap,
and minIdleBackup all to -1, saveOnRestart to false, then restart
Catalina.
-->
<!--
<Manager className="org.apache.catalina.session.PersistentManager"
debug="0"
saveOnRestart="true"
maxActiveSessions="-1"
minIdleSwap="-1"
maxIdleSwap="-1"
maxIdleBackup="-1">
<Store className="org.apache.catalina.session.FileStore"/>
</Manager>
-->
<Environment name="maxExemptions" type="java.lang.Integer"
value="15"/>
<Parameter name="context.param.name" value="context.param.value"
override="false"/>
<Resource name="jdbc/EmployeeAppDb" auth="SERVLET"
type="javax.sql.DataSource"/>
<Resource name="jdbc/TestDB"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/TestDB">
<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 0 for no limit.
-->
<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>user</name>
<value>javauser</value>
</parameter>
<parameter>
<name>password</name>
<value>javadude</value>
</parameter>
<!-- Class name for mm.mysql JDBC driver -->
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</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:mysql://localhost:3306/javatest?autoReconnect=true</value>
</parameter>
</ResourceParams>
<Resource name="mail/Session" auth="Container"
type="javax.mail.Session"/>
<ResourceParams name="mail/Session">
<parameter>
<name>mail.smtp.host</name>
<value>localhost</value>
</parameter>
</ResourceParams>
<ResourceLink name="linkToGlobalResource"
global="simpleValue"
type="java.lang.Integer"/>
</Context>
</Host>
</Engine>
</Service>
<!-- The MOD_WEBAPP connector is used to connect Apache 1.3 with Tomcat 4.0
as its servlet container. Please read the README.txt file coming with
the WebApp Module distribution on how to build it.
(Or check out the "jakarta-tomcat-connectors/webapp" CVS repository)
To configure the Apache side, you must ensure that you have the
"ServerName" and "Port" directives defined in "httpd.conf". Then,
lines like these to the bottom of your "httpd.conf" file:
LoadModule webapp_module libexec/mod_webapp.so
WebAppConnection warpConnection warp localhost:8008
WebAppDeploy examples warpConnection /examples/
The next time you restart Apache (after restarting Tomcat, if needed)
the connection will be established, and all applications you make
visible via "WebAppDeploy" directives can be accessed through Apache.
-->
<!-- Define an Apache-Connector Service -->
<!--
<Service name="Tomcat-Apache">
<Connector className="org.apache.catalina.connector.warp.WarpConnector"
port="8008" minProcessors="5" maxProcessors="75"
enableLookups="true" appBase="webapps"
acceptCount="10" debug="0"/>
<Engine className="org.apache.catalina.connector.warp.WarpEngine"
name="Apache" debug="0">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="apache_log." suffix=".txt"
timestamp="true"/>
<Realm className="org.apache.catalina.realm.MemoryRealm" />
</Engine>
</Service>
-->
</Server>
Pleas4 help!!!you have your driver jar in Tomcat\common\lib?
if so, check your classpath, it could be that. -
Weblogic 7.0 , MySQL 3.23 JDBC Connection Pools
i am using weblogic 7.0 and MySQL 3.23 and right now my objective is to create,
configure and test a JDBC
connection pool using the Administrative console.
Here is what i have done till now
- set the classpath of the MySQL driver in the startWLS.cmd like this
SET MYSQL_DRIVER=C:\mysqldriver\mysql-connector-java-2.0.14\mysql-connector-java-2.0.14-bin.jar
set CLASSPATH=%MYSQL_DRIVER%;%CLASSPATH%
- using the weblogic administrative console i have created a new connection pool
named as
testpool.
- Here is what i have in the testpool general tab
Name: testpool
URL: jdbc:mysql//localhost:3306/test (test is the name of the database in mysql)
Driver Classname: org.gjt.mm.mysql.Driver
I have not entered any Properties, ACL Name, Password or Open String Password.
- Now i go the the Testing tab and enter a name of a table in my test database
and click on Apply
and on the command window i am getting the following exception
java.sql.SQLException No suitable driver
Thanks in advance,
AshishThanks a lot Slava. After reading your mail and the post i was able to get it working.
"Slava Imeshev" <[email protected]> wrote:
Hi Ashish,
I figured out what's the problem. URL in the connection pool
definition is malformed. It's
jdbc:mysql//localhost:3306/test
while the correct one should have colon after mysql:
jdbc:mysql://localhost:3306/test
Regards,
Slava Imeshev
"Ashish Sureka" <[email protected]> wrote in message
news:[email protected]...
I am sorry, the program that i posted here is not comming properlyformatted but
i am able to run a simple java program that connects to MySQL and alsoa
servlet
that connects to the MySQL. The only problem i am having is includingthe
MySQL
driver jar files to the weblogic server classpath.
Thanks,
Ashish.
"Ashish Sureka" <[email protected]> wrote:
Hello Joseph Weinstein,
Actually, i already tried the same approach that you have mentioned
in
your reply
before i posted my message here. Following is the program that i use
to check
MySQL connection.
import java.sql.*;
public class MySQLConnect
public static void main(String[] args) throws Exception
try {
Class.forName ( "org.gjt.mm.mysql.Driver" );
System.out.println ( "MySQL Driver Found" );
} catch ( java.lang.ClassNotFoundException e ) {
System.out.println("MySQL JDBC Driver not found ... ");
throw ( e );
String url = "";
Connection con = null;
try {
url = "jdbc:mysql://" + "localhost:3306" + "/" + "test";
con = DriverManager.getConnection(url);
System.out.println("Connection established to " + url + "");
} catch ( java.sql.SQLException e ) {
System.out.println("Connection couldn't be established to " + url);
String sqlStatement = "SELECT * FROM testtable";
try {
Statement s = con.createStatement();
s.execute (sqlStatement);
s.close ( );
} catch ( SQLException e ) {
System.out.println ( "Error executing sql statement" );
con.close();
The classpath that i use to run this program is
SET PATH=C:\bea\jdk131_03\bin
SETCLASSPATH=C:\bea\jdk131_03\jre\lib\rt.jar;C:\bea\weblogic700\ebcc\lib\ext\se
rvlet.jar;C:\CSC413\Demos\HelloApp\HelloAppJAR
SET CLASSPATH=%CLASSPATH%;C:\bea\weblogic700\server\lib\weblogic.jar
SETMYSQL_DRIVER=C:\mysqldriver\mysql-connector-java-2.0.14\mysql-connector-java
-2.0.14-bin.jar
set CLASSPATH=.;%MYSQL_DRIVER%;%CLASSPATH%
I have also written a Servlet which checks the MySQL connection. For
the servlet
i added the MySQL driver jar files in the WEB-INF/lib directory ofthe
servlet
web application and it is working fine.
do you want me to attach the startWLS.cmd file that i changed to include
the MySQL
driver classpath.
Thanks for your replies,
Ashish.
Joseph Weinstein <[email protected]> wrote:
Ashish Sureka wrote:
When i start the weblogic server using the command prompt by executingthe startWLS.cmd,
i can see the classpath the server is using on the command window
and
that includes
the jar file for the MySQL driver but still it is throwing a
SQLException
and
saying that No Suitable driver.
How do i include a external library or jar file on the weblogic
server's
classpath.
is there a specific directory where i should put the MySQL driver
jar
file .
Thanks,
Ashish.No. Let's simplfy the problem. Please run a tiny standalone Java
program
that
just makes a JDBC connection to your MySQL DBMS, with no weblogic
code in the picture. When you succeed at this, show me the CLASSPATH
and
PATH of the shell that ran the program successfully, and show methe
few lines
of code that made the connection. Then we will know the problem.It
may
be that
the URL you're passing to the pool is not exactly correct for that
driver.
Joe
Joseph Weinstein <[email protected]> wrote:
Ashish Sureka wrote:
i am using weblogic 7.0 and MySQL 3.23 and right now my objective
is
to create,
configure and test a JDBC
connection pool using the Administrative console.
Here is what i have done till now
- set the classpath of the MySQL driver in the startWLS.cmd
like
this
SET
MYSQL_DRIVER=C:\mysqldriver\mysql-connector-java-2.0.14\mysql-connector-java
-2.0.14-bin.jar
set CLASSPATH=%MYSQL_DRIVER%;%CLASSPATH%
- using the weblogic administrative console i have created anew
connection
pool
named as
testpool.
- Here is what i have in the testpool general tab
Name: testpool
URL: jdbc:mysql//localhost:3306/test (test is the name of
the
database
in mysql)
Driver Classname: org.gjt.mm.mysql.Driver
I have not entered any Properties, ACL Name, Password or
Open
String
Password.
- Now i go the the Testing tab and enter a name of a table in
my
test
database
and click on Apply
and on the command window i am getting the following exception
java.sql.SQLException No suitable driverWatch the first lines that the server prints out when the script
starts
it. The script
shows the classpath that was constructed for the server. It is
likely
that you need
to do something else to ensure your driver is really in the classpath
the server uses.
Joe
Thanks in advance,
Ashish -
Problem creating connection pool to mysql database
Please, do not ignore this message and help me, if you have any Idea
I have Sun Java System Application Server 8.1 installed on my computer, I installed also MySQL Connector/J to access MySql Databases through JDBC
But now when I try to create new connection pool, an error comes:
Following parameter were used:
Name: MYSQL1
Resource Type: javax.sql.XADataSource
Database Vendor: mysql
Datasource Classname: com.mysql.jdbc.Driver
serverName 192.168.0.152
port 3306
networkProtocol
user testuser
password ***
databaseName test
datasourceName
After saving and then klicking on Ping button, following error comes: "An error has occurred.
Operation 'pingConnectionPool' failed in 'resources' Config Mbean. Target exception message: com.mysql.jdbc.Driver"
I checked the logs of MySql, there was no attempt to access given Database or MYSQL-server at all
What Am I doing wrong? How can I create MySql connection under Sun Java System Application Server 8.1?
Any help will be appreciatedThe driver is in right place
Originally I placed him in wrong directory and got an error, indicationg, that Driver class is not found, but then I corrected it, The problem is in connection to database - it doesn't work.
I tired to load the same driver into Netbeans and could easyli create a connection to database, but I get it not working ander Sun Application server -
Can anyone tell me all necessary steps required to create a connection pool to
MySQL and use the datasource to get the connection in BMP beans
Thanks in advance
TharaUsing weblogic's mssql driver:
define following configuration in your config.xml.
<JDBCConnectionPool
Name="MSSQLPool"
Targets="myserver"
URL="jdbc:weblogic:mssqlserver4"
DriverName="weblogic.jdbc.mssqlserver4.Driver"
InitialCapacity="0"
MaxCapacity="20"
CapacityIncrement="1"
Properties="user=jmsqa;password=jmsqa123;server=lcdbnt4"
/>
<JDBCDataSource
Name="jdbc.pool.testpool"
Targets="myserver"
JNDIName="jdbc.pool.testpool"
PoolName="testpool"
/>
Also, do following to make sure your environment is set.
java utils.dbping MSSQLSERVER4 USER PASS DBNAME@HOST:PORT
Thara wrote:
Can anyone tell me all necessary steps required to create a connection pool to
MySQL and use the datasource to get the connection in BMP beans
Thanks in advance
Thara -
Connection pool issues with Mysql
Hi,
I have defined sufficient read connections (50) in the toplink configuration, I am finding toplink is not releasing the connections in Mysql, this is when run from Jboss App server.
Is anyone aware of toplink connection pool issues with MySql?
thanksTopLink always closes connections, I cannot see how this could occur.
Please include your persistence.xml or sessions.xml. Also ensure you are closing your EntityManager or ClientSession, especially if using exclusive connections.
Also include the exception you are getting.
James : http://www.eclipselink.org -
Help Please: How to make a connection pool with mySQL
Hi,
I am learning the example codes shipped with weblogic server, which is under ...samples\examples\ejb20\basic\beanManaged. The original connection pool was on cloudscape. I was trying to modify it and make it connect to mySQL.
In ejb-jar.xml and weblogic-ejb-jar.xml, I replaced "demopool" (which was the original pool name) with "demopool1".
After starting the server, I tried to configure a new connection pool as following:
Name: demopool1
URL: jdbc:mysql:///test
Driver Classname: org.gjt.mm.mysql.Driver
Properties
(key=value): user=none
server=none
But I got the following errors:
<2007-10-5 ??06?30?09?> <Error> <JDBC> <Cannot startup connection pool "demopool1" Cannot load driver class: org.gjt.mm.mysql.Driver>
What should I do to let the server find the Driver?
Thanks a lot.Hong Qu wrote:
Thank you Joe,
I added the jar file location to the startExampleServer script. But when I tried to configure the Tx Data Sources from the console, I got the following error:
<2007-10-5 ??08?35?17?> <Notice> <WebLogicServer> <Started WebLogic Admin Server "examplesServer" for domain "examples" running in Development Mode>
setEntityContext called
ejbFindByPrimaryKey (ID: 0)
Failed to lookup JDBC Datasource. Please double check that
the JNDI name defined in the resource-description of the
EJB's weblogic-ejb-jar.xml file is the same as the JNDI name
for the Datasource defined in your config.xml.
<2007-10-5 ??08?38?16?> <Error> <JDBC> <Error during Data Source creation:
weblogic.common.ResourceException: DataSource(examples-dataSource-demoPool1)
can't be created with non-existent Pool (connection or multi) (demoPool1)>>
Do you know where is wrong?
Another problem is the connection method in AccountBean.java:
private Connection getConnection()
throws SQLException
InitialContext initCtx = null;
try {
initCtx = new InitialContext();
DataSource ds = (javax.sql.DataSource)
initCtx.lookup("java:comp/env/jdbc/demoPool");First verify from the console that a pool 'demoPool1' exists and
that you can test it from the console. Then find the DataSource
you associated with that pool. For an EJB I would suggest a
TxDataSource. You defined some JNDI name for the DataSource. Use
that name in the lookup. For instance, if your DataSource's
JNDI name is 'MyDataSource', the code should do this:
DataSource ds = (javax.sql.DataSource)
initCtx.lookup("MyDataSource");
return ds.getConnection();
} catch(NamingException ne) {
log("Failed to lookup JDBC Datasource. Please double check that");
log("the JNDI name defined in the resource-description of the ");
log("EJB's weblogic-ejb-jar.xml file is the same as the JNDI name ");
log("for the Datasource defined in your config.xml.");
throw new EJBException(ne);
} finally {
try {
if(initCtx != null) initCtx.close();
} catch(NamingException ne) {
log("Error closing context: " + ne);
throw new EJBException(ne);
I couldn't figure out what "java:comp/env/jdbc/demoPool" was related, so I just replaced "demopool" with "demopool1". Do you konw what "comp/env/jdbc" mean? Is it a location?
Thank you so much.
Iris
Maybe you are looking for
-
When I hit my iTunes icon I get an error message that says "this copy is corrupted or not installed correctly. Please reinstall iTunes". So, my question is, if I reinstall iTunes will my music library be wiped out?
-
Charging iPod touch with old AC-Firewire adapter?
Hello, I just recently bought an iPod touch, and wanted to know if it will work to charge it with the AC-Firewire adapter from my 2nd gen iPod. I also have the car charger for the 2nd gen. There are posts about doing it with an AC-usb adapter, but I
-
Good afternoon. My iphone 4s used in Amerke another user. When you upgrade requests id and password. I can not get it, what to do?
-
How to achive this using analytical function-- please help
version 10g. this code works just fine with my requirement. i am tyring to learn analytical functions and implement that in the below query. i tried using row_number , but i could nt achive the desired results. please give me some ideas. SELECT c.tax
-
Send the adobe form through webservices
Hello all, i have a requirement in adobe form. When i click on submit button the total pdf form have to be sent through webservices and update as a string in a SAP ztable. so that i can retrieve the string and convert it into pdf again and reuse it.