----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files. Don't make us guess your problem!!!
----------------------------------------------------------------
Hi folks,
I am using Windows NT 4.0 plus JDK1.2.1 plus Apache 1.3.12 plus JSERV1.0.
I have written a class to read the DataBase through a JDBC/ODBC bridge, but
I am afraid it is not throwing objects to garbage or closing connections.
Everytime I call any Servlet that uses this class, it works fine but the
amount of memory used by "java.exe" process increases by 200k or more. So,
after some repeated calls to any Servlet, java.exe is so big that it stops
working and I cant run Servlets anymore. The error in the log file says
"Jdbc:Odbc : canīt read anymore tables".
I am sending you the code of the class 1 that access the DB , the code of
class 2 that extends the HttpServlet class, and the code of class 3 that
extends class2. The problem is I dont know how to close the connection to
the database after the ResultSet is passed to the CLASS3 (see codes, I hope
you do!)
Thanks in advance,
Gustavo Arruda
//CLASS 1 - DBSynchronizer - Access the DB through methods select and update
import java.io.*;
import java.sql.*;
public class DBSynchronizer {
private static final String url="jdbc:odbc:carona";
private static boolean isReading = false;
private static boolean isWriting = false;
private static Connection readCon;
private static Connection writeCon;
private static Statement select = null;
private static Statement update = null;
private static ResultSet result = null;
public DBSynchronizer() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
readCon = DriverManager.getConnection(url,"","");
writeCon = DriverManager.getConnection(url,"","");
} catch (Exception e) {}
}
public synchronized ResultSet select(String query) {
while (isWriting) try {
wait();
} catch (InterruptedException e) { }
isReading = true;
try {
select = readCon.createStatement();
result = select.executeQuery(query}
catch(Exception e) {
e.printStackTrace();
}
isReading = false;
notifyAll();
return result;
}
public synchronized int update(String updt) {
int inserted=0;
while (isReading) try {
wait();
} catch (InterruptedException e) { }
isWriting = true;
try {
update = writeCon.createStatement();
inserted=update.executeUpdate(updt);
} catch(Exception e) {
inserted=-1;
}
isWriting = false;
notifyAll();
return inserted;
}
}
//CLASS2 - HttpServletSQL makes the CLASS1 methods available through an
object called sql
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HttpServletSQL extends HttpServlet {
protected static DBSynchronizer sql;
public void init (ServletConfig config) throws ServletException {
super.init(config);
// Created only by the first Servlet
if(sql == null)
sql = new DBSynchronizer();
}
}
}
//CLASS3 - A normal servlet that extends class2
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
public class Servlet_counter extends HttpServletSQL {
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
String fontSize = req.getParameter("fontSize");
String fontColor = req.getParameter("fontColor");
if (fontSize == null) fontSize = "2" ;
if (fontColor == null) fontColor = "white" ;
String getCod = "Select Max(Cod) AS MCOD FROM ACCESS" ;
ResultSet rs= sql.select(getCod);
int cod = 0;
try {
if (rs.next()) {
cod = rs.getInt(1);
out.print("<font size=+"+fontSize+" color="+fontColor+"> "+
(cod+1)+"</font>");
}
rs.close();
}
catch(Exception e) { }
}
}
--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search Archives:
<http://www.mail-archive.com/java-apache-users%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]