You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael Ni <mi...@hotmail.com> on 2007/01/05 21:43:14 UTC

web application - student need help

Hi i'm doing a web application to help manage players for the online game 
Final Fantasy XI.

Im using tomcat, sqlserver2000, and jsp.

both sqlserver and tomcat are set up on the same computer.
computer is pentium 2.8 GHZ with 512 RAM.
im on cable internet

the web application uses simple queries, like search a table for a certain 
condition.  i realize when multiple people access the database it hangs, and 
causes the jsp pages to error.

Is it mainly tomcat, or sql server?  anyone have any experience on setting 
up websites to handle a lot of traffic?

here is my site project
http://66.215.70.71/

thx
mike

_________________________________________________________________
Get FREE Web site and company branded e-mail from Microsoft Office Live 
http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by Andre Prasetya <an...@gmail.com>.
When the jsp shows error, its about exception right ? what is the exception
and what does it says ?

On 1/6/07, Michael Ni <mi...@hotmail.com> wrote:
>
> Hi i'm doing a web application to help manage players for the online game
> Final Fantasy XI.
>
> Im using tomcat, sqlserver2000, and jsp.
>
> both sqlserver and tomcat are set up on the same computer.
> computer is pentium 2.8 GHZ with 512 RAM.
> im on cable internet
>
> the web application uses simple queries, like search a table for a certain
> condition.  i realize when multiple people access the database it hangs,
> and
> causes the jsp pages to error.
>
> Is it mainly tomcat, or sql server?  anyone have any experience on setting
> up websites to handle a lot of traffic?
>
> here is my site project
> http://66.215.70.71/
>
> thx
> mike
>
> _________________________________________________________________
> Get FREE Web site and company branded e-mail from Microsoft Office Live
> http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
-Andre-

People see things the way they are and say "why ?" I see things that never
were and say "Why not ?"

Re: web application - student need help

Posted by Darek Czarkowski <dc...@infinitesource.ca>.
Michael Ni wrote:
>
> public ResultSet getData(String queryStr) throws Exception
>     {
>
>         try {
>             DBConstants db = new DBConstants();
>             Class.forName(db.getDrivername());
>             Connection conn;
>             conn = 
> DriverManager.getConnection("jdbc:microsoft:sqlserver://" + 
> db.getHostname() + "","" + db.getUsername() + "","" + db.getPassword() 
> + "");
>
>
>             Statement stmt = conn.createStatement();
>             ResultSet rs = stmt.executeQuery(queryStr);
>             return rs;
>         }
>         catch(Exception e) {
>             e.printStackTrace();
>             System.out.println("getData error");
>             throw new Exception();
>         }
>     }
>
Add

|finally {
      try {if (rs != null) rs.close();} catch (SQLException e) {}
      try {if (stmt != null) stmt.close();} catch (SQLException e) {}
      try {if (conn != null) conn.close();} catch (SQLException e) {}
    }|

And return an object rather than ResultSet.

Read about connection pooling, here is an example:
http://www.onjava.com/pub/a/onjava/2006/04/19/database-connection-pooling-with-tomcat.html?page=1

-- 
Darek Czarkowski
www.infinitesource.ca
darekc at infinitesource dot ca 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael,

Michael Ni wrote:
> even with connection pooling, how many connections are we looking at
> here?  if my project works as intended, im predicting from 30 to 1000
> poeple simultaneously hitting tomcat and sql server.

What you really need to know is how many database queries will will need
to support. Just because 1000 people may be logged-in at the same time
doesn't mean that you have to handle 1000 simultaneous requests.

You might be able to get away with as few as 50 connections in your pool
to start out with. You are likely to experience slow growth at the
beginning, so just do your own wall-clock testing on the live site
occasionally to determine if it's "fast enough".

> i remember when websites like friendster.com came out, it was really
> slow.  now it is much faster, do you guys know where does a student
> learn about how to handle high traffic web applications?  is there any
> classes?

Tuning like this is a black art. You really need to either get someone
who knows what they are doing, or stumble through it yourself.

Want my advice? Put it out there and see how it performs. If it sucks,
make improvements. Make sure you have your database well-optimized. Most
database rely not only on indexes (which are so important I cannot
stress that enough) but also on their own black magic that analyzes the
actual content of the tables for optimization. Often, you can simply
issue an OPTIMIZE TABLE query on the table and make it perform better.

Some database perform better than others. For instance, I think that
MySQL cannot be beat when it comes to read-only queries. They also have
a handful of different table types that makes it easy to optimize for
your expected usage (for instance, if you don't need transactions, you
can use a /much/ faster table implementation and get better performance).

Good luck!

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFntWX9CaO5/Lv0PARAndeAJ9m3BTh5VC2EyXEVjkU8JXp4KcLHACdH59l
m64lXBbWkKaosUzw0Z+5q6M=
=Gayw
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by Dhaval Patel <dh...@yahoo.com>.
Hi,

Following is configuration for Tomcat Connection pool which you have to write in your context.xml.
If you are using Tomcat Admin, you specify parameters in web GUI. 

<Resource name="jdbc/mydbconn" type="javax.sql.DataSource" />
  <ResourceParams name="jdbc/mydbconn">
    <parameter>
      <name>maxWait</name>
      <value>5000</value>
    </parameter>
    <parameter>
      <name>maxActive</name>
      <value>10</value>
    </parameter>
    <parameter>
      <name>url</name>
      <value>*JDBC URL*</value>
    </parameter>
    <parameter>
      <name>driverClassName</name>
      <value>*DRIVER CLASS*</value>
    </parameter>
    <parameter>
      <name>maxIdle</name>
      <value>2</value>
    </parameter>
    <parameter>
      <name>username</name>
      <value>*DB USERNAME*</value>
    </parameter>
    <parameter>
      <name>password</name>
      <value>*DB PASSWORD*</value>
    </parameter>
  </ResourceParams>

Please refer to documentation
(http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html) if you want fine
tune parameters like maxWait, maxActive, maxIdle, etc. and believe me you will find it very
useful.

Now how to use that connection in your application pages. Following is the code snippet that you
can use it.

Context init = new InitialContext();
Context ctx = (Context) init.lookup("java:comp/env");
DataSource ds = (DataSource) ctx.lookup("jdbc/mydbconn"); //BE CAREFUL ABOUT NAME - jdbc/mydbconn.

public ... getData(...)
    {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try
        {
            conn = ds.getConnection();
            stmt = conn.createStatement();
            ...
            ...
            ...
            rs.close();
            rs = null;
            stmt.close();
            stmt = null;
            conn.close(); // Return to connection pool
            conn = null;
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        finally
        {
            // Always make sure result sets and statements are closed,
            // and the connection is returned to the pool
            if (rs != null)
            {
                try
                { rs.close(); } catch (SQLException e)
                { ; }
                rs = null;
            }
            if (stmt != null)
            {
                try
                { stmt.close(); } catch (SQLException e)
                { ; }
                stmt = null;
            }
            if (conn != null)
            {
                try
                { conn.close(); } catch (SQLException e)
                { ; }
                conn = null;
            }            
        }        
        ...
    }

Also you can write generic bean and use it in your JSP pages. This way it will ease your work.

About making website faster, there are many parameters involved. Above thing will definitely gain
speed if you fine tune it based upon your application and hardware. Now if you want more speed,
you can go with better hardware or provide more memory to tomcat. But first try above snippet. I
am sure you won't need another machine.


Regards,
D
--- Michael Ni <mi...@hotmail.com> wrote:

> great replies from everyone.
> 
> even with connection pooling, how many connections are we looking at here?  
> if my project works as intended, im predicting from 30 to 1000 poeple 
> simultaneously hitting tomcat and sql server.
> 
> i remember when websites like friendster.com came out, it was really slow.  
> now it is much faster, do you guys know where does a student learn about how 
> to handle high traffic web applications?  is there any classes?
> 
> 
> >From: Christopher Schultz <ch...@christopherschultz.net>
> >Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
> >To: Tomcat Users List <us...@tomcat.apache.org>
> >Subject: Re: web application - student need help
> >Date: Fri, 05 Jan 2007 17:10:13 -0500
> >
> >-----BEGIN PGP SIGNED MESSAGE-----
> >Hash: SHA1
> >
> >Michael,
> >
> >Michael Ni wrote:
> > > i don't get any error when there isn't that much traffic
> > >
> > > but i dont close my jdbc connections, could that be a problem?
> >
> >Oooooh, yeah. Failing to close connections is very likely to give you
> >errors, as you will end up running out of memory, or the database server
> >will cut you off when you reach the maximum number of connections.
> >
> >Someone else mentioned the use of a connection pool, which I highly
> >recommend. You can use Tomcat to configure a connection pool and then
> >obtain a JDBC DataSource through JNDI. Then, you can get a connection
> >from that for use.
> >
> >It's not really as complicated as it sounds ;)
> >
> > >         try {
> > >             DBConstants db = new DBConstants();
> > >             Class.forName(db.getDrivername());
> > >             Connection conn;
> > >             conn =
> > > DriverManager.getConnection("jdbc:microsoft:sqlserver://" +
> > > db.getHostname() + "","" + db.getUsername() + "","" + db.getPassword() +
> > > "");
> > >
> > >
> > >             Statement stmt = conn.createStatement();
> > >             ResultSet rs = stmt.executeQuery(queryStr);
> > >             return rs;
> > >         }
> > >         catch(Exception e) {
> > >             e.printStackTrace();
> > >             System.out.println("getData error");
> > >             throw new Exception();
> > >         }
> > >     }
> >
> >Let me suggest some changes to your code:
> >
> >Connection conn = null;
> >Statement stmt = null;
> >ResultSet rs = null;
> >
> >try
> >{
> >     conn = (get connection from jndi datasource)
> >     stmt = conn.createStatement();
> >     rs = stmt.executeQuery(queryStr);
> >
> >     // Package the results into Java objects
> >     // instead of using the ResultSet directly
> >
> >     return ??;
> >}
> >catch (SQLException sqle)  // Don't catch "Exception" unless you have to
> >{
> >     sqle.printStackTrace();
> >     System.err.println("getData error");  // System.err is better
> >
> >     throw sqle; // No need for a new exception; use existing one
> >}
> >finally
> >{
> >     if(null != rs)
> >         try { rs.close(); } catch (SQLException sqle)
> >         { System.err.println("Could not close ResultSet"); }
> >     if(null != stmt)
> >         try { stmt.close(); } catch (SQLException sqle)
> >         { System.err.println("Could not close Statement"); }
> >     if(null != conn)
> >         try { conn.close(); } catch (SQLException sqle)
> >         { System.err.println("Could not close Connection"); }
> >}
> >
> >This is about as clean as you can get. If you must return the ResultSet
> >to to the calling method, then you will have to do something different.
> >I recommend you copy from the ResultSet into something like an
> >ArraryList of objects specific for your needs.
> >
> >One last thing: when possible, use PreparedStatement instead of
> >Statement for your queries. The use of this class goes a long way
> >towards protecting you against SQL injection attacks (where people can
> >do nasty things like drop tables and stuff). It requires a bit more
> >setup (especially if you are trying to write a reusable method to
> >execute all your queries) but I think it's worth it.
> >
> >- -chris
> >-----BEGIN PGP SIGNATURE-----
> >Version: GnuPG v1.4.6 (MingW32)
> >Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> >
> >iD8DBQFFnszE9CaO5/Lv0PARAjlpAJ9yhTlVRo5InvBnHsTIlTpIHJ5/+wCgtZMx
> >SoN9PKZ3jxEx4YflzuLg97o=
> >=3nJD
> >-----END PGP SIGNATURE-----
> >
> >---------------------------------------------------------------------
> >To start a new topic, e-mail: users@tomcat.apache.org
> >To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >For additional commands, e-mail: users-help@tomcat.apache.org
> >
> 
> _________________________________________________________________
> Get live scores and news about your team: Add the Live.com Football Page 
> www.live.com/?addtemplate=football&icid=T001MSN30A0701
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by Michael Ni <mi...@hotmail.com>.
great replies from everyone.

even with connection pooling, how many connections are we looking at here?  
if my project works as intended, im predicting from 30 to 1000 poeple 
simultaneously hitting tomcat and sql server.

i remember when websites like friendster.com came out, it was really slow.  
now it is much faster, do you guys know where does a student learn about how 
to handle high traffic web applications?  is there any classes?


>From: Christopher Schultz <ch...@christopherschultz.net>
>Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
>To: Tomcat Users List <us...@tomcat.apache.org>
>Subject: Re: web application - student need help
>Date: Fri, 05 Jan 2007 17:10:13 -0500
>
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Michael,
>
>Michael Ni wrote:
> > i don't get any error when there isn't that much traffic
> >
> > but i dont close my jdbc connections, could that be a problem?
>
>Oooooh, yeah. Failing to close connections is very likely to give you
>errors, as you will end up running out of memory, or the database server
>will cut you off when you reach the maximum number of connections.
>
>Someone else mentioned the use of a connection pool, which I highly
>recommend. You can use Tomcat to configure a connection pool and then
>obtain a JDBC DataSource through JNDI. Then, you can get a connection
>from that for use.
>
>It's not really as complicated as it sounds ;)
>
> >         try {
> >             DBConstants db = new DBConstants();
> >             Class.forName(db.getDrivername());
> >             Connection conn;
> >             conn =
> > DriverManager.getConnection("jdbc:microsoft:sqlserver://" +
> > db.getHostname() + "","" + db.getUsername() + "","" + db.getPassword() +
> > "");
> >
> >
> >             Statement stmt = conn.createStatement();
> >             ResultSet rs = stmt.executeQuery(queryStr);
> >             return rs;
> >         }
> >         catch(Exception e) {
> >             e.printStackTrace();
> >             System.out.println("getData error");
> >             throw new Exception();
> >         }
> >     }
>
>Let me suggest some changes to your code:
>
>Connection conn = null;
>Statement stmt = null;
>ResultSet rs = null;
>
>try
>{
>     conn = (get connection from jndi datasource)
>     stmt = conn.createStatement();
>     rs = stmt.executeQuery(queryStr);
>
>     // Package the results into Java objects
>     // instead of using the ResultSet directly
>
>     return ??;
>}
>catch (SQLException sqle)  // Don't catch "Exception" unless you have to
>{
>     sqle.printStackTrace();
>     System.err.println("getData error");  // System.err is better
>
>     throw sqle; // No need for a new exception; use existing one
>}
>finally
>{
>     if(null != rs)
>         try { rs.close(); } catch (SQLException sqle)
>         { System.err.println("Could not close ResultSet"); }
>     if(null != stmt)
>         try { stmt.close(); } catch (SQLException sqle)
>         { System.err.println("Could not close Statement"); }
>     if(null != conn)
>         try { conn.close(); } catch (SQLException sqle)
>         { System.err.println("Could not close Connection"); }
>}
>
>This is about as clean as you can get. If you must return the ResultSet
>to to the calling method, then you will have to do something different.
>I recommend you copy from the ResultSet into something like an
>ArraryList of objects specific for your needs.
>
>One last thing: when possible, use PreparedStatement instead of
>Statement for your queries. The use of this class goes a long way
>towards protecting you against SQL injection attacks (where people can
>do nasty things like drop tables and stuff). It requires a bit more
>setup (especially if you are trying to write a reusable method to
>execute all your queries) but I think it's worth it.
>
>- -chris
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.4.6 (MingW32)
>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>iD8DBQFFnszE9CaO5/Lv0PARAjlpAJ9yhTlVRo5InvBnHsTIlTpIHJ5/+wCgtZMx
>SoN9PKZ3jxEx4YflzuLg97o=
>=3nJD
>-----END PGP SIGNATURE-----
>
>---------------------------------------------------------------------
>To start a new topic, e-mail: users@tomcat.apache.org
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>

_________________________________________________________________
Get live scores and news about your team: Add the Live.com Football Page 
www.live.com/?addtemplate=football&icid=T001MSN30A0701


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael,

Michael Ni wrote:
> i don't get any error when there isn't that much traffic
> 
> but i dont close my jdbc connections, could that be a problem?

Oooooh, yeah. Failing to close connections is very likely to give you
errors, as you will end up running out of memory, or the database server
will cut you off when you reach the maximum number of connections.

Someone else mentioned the use of a connection pool, which I highly
recommend. You can use Tomcat to configure a connection pool and then
obtain a JDBC DataSource through JNDI. Then, you can get a connection
from that for use.

It's not really as complicated as it sounds ;)

>         try {
>             DBConstants db = new DBConstants();
>             Class.forName(db.getDrivername());
>             Connection conn;
>             conn =
> DriverManager.getConnection("jdbc:microsoft:sqlserver://" +
> db.getHostname() + "","" + db.getUsername() + "","" + db.getPassword() +
> "");
> 
> 
>             Statement stmt = conn.createStatement();
>             ResultSet rs = stmt.executeQuery(queryStr);
>             return rs;
>         }
>         catch(Exception e) {
>             e.printStackTrace();
>             System.out.println("getData error");
>             throw new Exception();
>         }
>     }

Let me suggest some changes to your code:

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try
{
    conn = (get connection from jndi datasource)
    stmt = conn.createStatement();
    rs = stmt.executeQuery(queryStr);

    // Package the results into Java objects
    // instead of using the ResultSet directly

    return ??;
}
catch (SQLException sqle)  // Don't catch "Exception" unless you have to
{
    sqle.printStackTrace();
    System.err.println("getData error");  // System.err is better

    throw sqle; // No need for a new exception; use existing one
}
finally
{
    if(null != rs)
        try { rs.close(); } catch (SQLException sqle)
        { System.err.println("Could not close ResultSet"); }
    if(null != stmt)
        try { stmt.close(); } catch (SQLException sqle)
        { System.err.println("Could not close Statement"); }
    if(null != conn)
        try { conn.close(); } catch (SQLException sqle)
        { System.err.println("Could not close Connection"); }
}

This is about as clean as you can get. If you must return the ResultSet
to to the calling method, then you will have to do something different.
I recommend you copy from the ResultSet into something like an
ArraryList of objects specific for your needs.

One last thing: when possible, use PreparedStatement instead of
Statement for your queries. The use of this class goes a long way
towards protecting you against SQL injection attacks (where people can
do nasty things like drop tables and stuff). It requires a bit more
setup (especially if you are trying to write a reusable method to
execute all your queries) but I think it's worth it.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFnszE9CaO5/Lv0PARAjlpAJ9yhTlVRo5InvBnHsTIlTpIHJ5/+wCgtZMx
SoN9PKZ3jxEx4YflzuLg97o=
=3nJD
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by Martin Gainty <mg...@hotmail.com>.
start with DriverManagerConnectionFactory
http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/doc/ManualPoolingDriverExample.java?view=log

Then use a connection from the DriverManagerConnectionFactory to populate a Datasource
http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/doc/ManualPoolingDataSourceExample.java?view=log

jsp Example using PoolableConnectionFactory
http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/doc/poolingDriverExample.jocl.sample?view=log

I am not familiar with DBPoolBean (can you illustrate the location of the jars and working sample code..?)

I found this taglib code which build an options list (from a connection obtained from a ConnectionPool)
http://archives.java.sun.com/cgi-bin/wa?A2=ind0009&L=jsp-interest&P=57293

HTH,
M-
--------------------------------------------------------------------------- 
This e-mail message (including attachments, if any) is intended for the use of the individual or entity to which it is addressed and may contain information that is privileged, proprietary , confidential and exempt from disclosure. If you are not the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited.
--------------------------------------------------------------------------- 
Le présent message électronique (y compris les pièces qui y sont annexées, le cas échéant) s'adresse au destinataire indiqué et peut contenir des renseignements de caractère privé ou confidentiel. Si vous n'êtes pas le destinataire de ce document, nous vous signalons qu'il est strictement interdit de le diffuser, de le distribuer ou de le reproduire.

----- Original Message ----- 
From: "Caroline Jen" <ji...@yahoo.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Friday, January 05, 2007 4:42 PM
Subject: Re: web application - student need help


> Did you configure a connection pool in Tomcat?  Then,
> get a connection object from the pool for each data
> search method invocation.
> 
> I am at work now.  I do not have the configuration
> with me.  I can post the configuration and the
> database access code when I get home.
> 
> Meanwhile, do a search on the internet.
> --- Michael Ni <mi...@hotmail.com> wrote:
> 
>> i don't get any error when there isn't that much
>> traffic
>> 
>> but i dont close my jdbc connections, could that be
>> a problem?
>> 
>> this is the function i use to query
>> 
>>
> ----------------------------------------------------------------------------------------
>> public ResultSet getData(String queryStr) throws
>> Exception
>> {
>> 
>> try {
>> DBConstants db = new DBConstants();
>> Class.forName(db.getDrivername());
>> Connection conn;
>> conn =
>>
> DriverManager.getConnection("jdbc:microsoft:sqlserver://"
>> + 
>> db.getHostname() + "","" + db.getUsername() + "",""
>> + db.getPassword() + 
>> "");
>> 
>> 
>> Statement stmt = conn.createStatement();
>> ResultSet rs = stmt.executeQuery(queryStr);
>> return rs;
>> }
>> catch(Exception e) {
>> e.printStackTrace();
>> System.out.println("getData error");
>> throw new Exception();
>> }
>> }
>>
> ----------------------------------------------------------------------------------
>> 
>> then if i want to use it in a jsp page i will do
>> something like this
>>
> ------------------------------------------------------------------------
>> 
>> <%
>>   DBPoolBean dbpb = new DBPoolBean();
>> 
>>   ResultSet rs = dbpb.getData("SELECT * FROM drops
>> order by hnm, 
>> itemname_en");
>>   while ( rs.next() ) {
>>     out.println("<tr><td width=\"50\">" +
>> rs.getString("hnm") + " </td>");
>>     out.println("<td width=\"50\">" +
>> rs.getString("itemname_en") + " 
>> </td></tr>");
>>   }
>> %>
>> 
>> 
>> 
>> >From: Darek Czarkowski
>> <dc...@infinitesource.ca>
>> >Reply-To: "Tomcat Users List"
>> <us...@tomcat.apache.org>
>> >To: Tomcat Users List <us...@tomcat.apache.org>
>> >Subject: Re: web application - student need help
>> >Date: Fri, 05 Jan 2007 12:52:19 -0800
>> >
>> >Michael Ni wrote:
>> >>
>> >>the web application uses simple queries, like
>> search a table for a certain 
>> >>condition.  i realize when multiple people access
>> the database it hangs, 
>> >>and causes the jsp pages to error.
>> >Just a guess, your connection to the database is a
>> problem, perhaps errors 
>> >in queries, not closed connections.
>> >What are the error messages? (page/log)
>> >
>> >--
>> >Darek Czarkowski
>> >Ph: 604 294 6557 (Ext. 113)
>> >Fx: 604 294 6507
>> >www.infinitesource.ca
>> >darekc at infinitesource dot ca
>> >
>> >
>>
>>---------------------------------------------------------------------
>> >To start a new topic, e-mail:
>> users@tomcat.apache.org
>> >To unsubscribe, e-mail:
>> users-unsubscribe@tomcat.apache.org
>> >For additional commands, e-mail:
>> users-help@tomcat.apache.org
>> >
>> 
>>
> _________________________________________________________________
>> Type your favorite song. Get a customized station. 
>> Try MSN Radio powered 
>> by Pandora.
>> http://radio.msn.com/?icid=T002MSN03A07001
>> 
>> 
>>
> ---------------------------------------------------------------------
>> To start a new topic, e-mail:
>> users@tomcat.apache.org
>> To unsubscribe, e-mail:
>> users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail:
>> users-help@tomcat.apache.org
>> 
>> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
>

Re: web application - student need help

Posted by Michael Ni <mi...@hotmail.com>.
Hi Caroline,

first i want to thank you for the time you spent to answer my reply.
second, in your example, which imports are irrelavant to me?  i'm assuming i 
dont need any of the artimus stuff, whatever that is.

thanks
mike ni


>From: Caroline Jen <ji...@yahoo.com>
>Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
>To: Tomcat Users List <us...@tomcat.apache.org>
>Subject: Re: web application - student need help
>Date: Sun, 7 Jan 2007 15:59:16 -0800 (PST)
>
>For configuring a connection pool, follow this URL:
>http://jakarta.apache.org/commons/dbcp/configuration.html
>
>1. The JDBC driver JAR must go in the common/lib
>directory (because for connection pooling it needs to
>be accessible to
>both Tomcat and the web app).
>
>2. DBCP is built into Tomcat so you don't need to
>install a JAR for that.
>
>3. Always close the connection when you're done with
>it.
>
>The configuration shown below is what in my Tomcat's
>server.xml file:
>
>         <DefaultContext>
>	      <Resource name="jdbc/MySQLDB" auth="Container"
>		  type="javax.sql.DataSource"/>
>	      <ResourceParams name="jdbc/MySQLDB">
>                   <parameter>
>                         <name>factory</name>
>
><value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>                   </parameter>
>		  <parameter>
>		  	<name>driverClassName</name>
>		  	<value>com.mysql.jdbc.Driver</value>
>		  </parameter>
>		  <parameter>
>		   	<name>url</name>
>
><value>jdbc:mysql://localhost:3306/artimus?autoReconnect=true</value>
>		  </parameter>
>		  <parameter>
>		    	<name>username</name>
>		    	<value>javauser</value>
>		  </parameter>
>		  <parameter>
>		    	<name>password</name>
>		    	<value>javadude</value>
>		  </parameter>
>		  <parameter>
>		    	<name>maxActive</name>
>		    	<value>20</value>
>		  </parameter>
>		  <parameter>
>		    	<name>maxIdle</name>
>		    	<value>30</value>
>		  </parameter>
>		  <parameter>
>		    	<name>maxWait</name>
>		    	<value>10000</value>
>		  </parameter>
>                   <parameter>
>                         <name>removeAbandoned</name>
>                         <value>true</value>
>                   </parameter>
>                   <parameter>
>
><name>removeAbandonedTimeout</name>
>                         <value>60</value>
>                   </parameter>
>                   <parameter>
>                         <name>logAbandoned</name>
>                         <value>true</value>
>                   </parameter>
>
>               </ResourceParams>
>	</DefaultContext>
>
>     </Host>
>
>Then, the code to get a DB connection is:
>
>import java.sql.Connection;
>import java.sql.SQLException;
>import javax.naming.InitialContext;
>import javax.naming.NamingException;
>import javax.sql.DataSource;
>
>public class DBConnection
>{
>    public static Connection getDBConnection() throws
>SQLException
>    {
>       Connection conn = null;
>
>       try
>       {
>          InitialContext ctx = new InitialContext();
>          DataSource ds = ( DataSource ) ctx.lookup(
>"java:comp/env/jdbc/MySQLDB" );
>
>          try
>          {
>             conn = ds.getConnection();
>          }
>          catch( SQLException e )
>          {
>             System.out.println( "Open connection
>failure: " + e.getMessage() );
>          }
>       }
>       catch( NamingException nEx )
>       {
>          nEx.printStackTrace();
>       }
>       return conn;
>    }
>}
>
>Then, the code to use the DB connection:
>
>import java.io.IOException;
>import java.sql.Connection;
>import java.sql.ResultSet;
>import java.sql.Statement;
>import java.sql.PreparedStatement;
>import java.sql.SQLException;
>import java.sql.Timestamp;
>
>import java.util.ArrayList;
>import java.util.Collection;
>
>import org.apache.artimus.message.ThreadBean;
>import org.apache.artimus.message.PostBean;
>import org.apache.artimus.message.AttachmentBean;
>import
>org.apache.artimus.message.exceptions.MessageDAOSysException;
>import
>org.apache.artimus.message.exceptions.ObjectNotFoundException;
>import
>org.apache.artimus.message.exceptions.AssertionException;
>import
>org.apache.artimus.message.exceptions.DatabaseException;
>import
>org.apache.artimus.message.exceptions.BadInputException;
>import org.apache.artimus.ConnectionPool.DBConnection;
>
>public class MySQLMessageDAO implements MessageDAO
>{
>    public void createThread( String receiver, String
>sender, String title,
>                              String
>lastPostMemberName, String threadTopic,
>                              String threadBody,
>Timestamp threadCreationDate,
>                              Timestamp
>threadLastPostDate, int threadType,
>                              int threadOption, int
>threadStatus, int threadViewCount,
>                              int threadReplyCount, int
>threadDuration )
>                              throws
>MessageDAOSysException
>    {
>       Connection conn = null;
>       PreparedStatement stmt = null;
>       String insertSQL = "INSERT INTO message_thread(
>message_receiver, message_sender, article_title,
>last_post_member_name, thread_topic, thread_body,
>thread_creation_date, thread_last_post_date,
>thread_type, thread_option, thread_status,
>thread_view_count, thread_reply_count, thread_duration
>) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
>
>       try
>       {
>          conn = DBConnection.getDBConnection();
>          stmt = conn.prepareStatement( insertSQL );
>
>          stmt.setString( 1, receiver );
>          stmt.setString( 2, sender );
>          stmt.setString( 3, title );
>          stmt.setString( 4, lastPostMemberName );
>          stmt.setString( 5, threadTopic );
>          stmt.setString( 6, threadBody );
>          stmt.setTimestamp( 7, threadCreationDate );
>          stmt.setTimestamp( 8, threadLastPostDate );
>          stmt.setInt( 9, threadType );
>          stmt.setInt( 10, threadOption );
>          stmt.setInt( 11, threadStatus );
>          stmt.setInt( 12, threadViewCount );
>          stmt.setInt( 13, threadReplyCount );
>          stmt.setInt( 14, threadDuration );
>
>          stmt.executeUpdate();
>          // m_dirty = true;
>       }
>       catch( SQLException se )
>       {
>          System.out.println( se.getMessage() );
>          se.printStackTrace();
>          throw new MessageDAOSysException( "Error
>executing SQL in ThreadHandler.createThread." );
>       }
>       finally
>       {
>          if ( conn != null )
>          {
>             try
>             {
>                stmt.close();
>                stmt = null;
>                conn.close();
>             }
>             catch( SQLException sqlEx )
>             {
>                System.out.println( "Problem occurs
>while closing " + sqlEx );
>             }
>             conn = null;
>          }
>       }
>    }
>}
>
>-Caroline
>--- Michael Ni <mi...@hotmail.com> wrote:
>
> > thx caroline
> >
> >
> > >From: Caroline Jen <ji...@yahoo.com>
> > >Reply-To: "Tomcat Users List"
> > <us...@tomcat.apache.org>
> > >To: Tomcat Users List <us...@tomcat.apache.org>
> > >Subject: Re: web application - student need help
> > >Date: Fri, 5 Jan 2007 13:42:18 -0800 (PST)
> > >
> > >Did you configure a connection pool in Tomcat?
> > Then,
> > >get a connection object from the pool for each data
> > >search method invocation.
> > >
> > >I am at work now.  I do not have the configuration
> > >with me.  I can post the configuration and the
> > >database access code when I get home.
> > >
> > >Meanwhile, do a search on the internet.
> > >--- Michael Ni <mi...@hotmail.com> wrote:
> > >
> > > > i don't get any error when there isn't that much
> > > > traffic
> > > >
> > > > but i dont close my jdbc connections, could that
> > be
> > > > a problem?
> > > >
> > > > this is the function i use to query
> > > >
> > > >
> >
> >----------------------------------------------------------------------------------------
> > > > public ResultSet getData(String queryStr) throws
> > > > Exception
> > > > 	{
> > > >
> > > > 		try {
> > > > 			DBConstants db = new DBConstants();
> > > > 			Class.forName(db.getDrivername());
> > > > 			Connection conn;
> > > > 			conn =
> > > >
> >
> >DriverManager.getConnection("jdbc:microsoft:sqlserver://"
> > > > +
> > > > db.getHostname() + "","" + db.getUsername() +
> > "",""
> > > > + db.getPassword() +
> > > > "");
> > > >
> > > >
> > > > 			Statement stmt = conn.createStatement();
> > > > 			ResultSet rs = stmt.executeQuery(queryStr);
> > > > 			return rs;
> > > > 		}
> > > > 		catch(Exception e) {
> > > > 			e.printStackTrace();
> > > > 			System.out.println("getData error");
> > > > 			throw new Exception();
> > > > 		}
> > > > 	}
> > > >
> >
> >----------------------------------------------------------------------------------
> > > >
> > > > then if i want to use it in a jsp page i will do
> > > > something like this
> > > >
> >
> >------------------------------------------------------------------------
> > > >
> > > > <%
> > > >   DBPoolBean dbpb = new DBPoolBean();
> > > >
> > > >   ResultSet rs = dbpb.getData("SELECT * FROM
> > drops
> > > > order by hnm,
> > > > itemname_en");
> > > >   while ( rs.next() ) {
> > > >     out.println("<tr><td width=\"50\">" +
> > > > rs.getString("hnm") + " </td>");
> > > >     out.println("<td width=\"50\">" +
> > > > rs.getString("itemname_en") + "
> > > > </td></tr>");
> > > >   }
> > > > %>
> > > >
> > > >
> > > >
> > > > >From: Darek Czarkowski
> > > > <dc...@infinitesource.ca>
> > > > >Reply-To: "Tomcat Users List"
> > > > <us...@tomcat.apache.org>
> > > > >To: Tomcat Users List <us...@tomcat.apache.org>
> > > > >Subject: Re: web application - student need
> > help
> > > > >Date: Fri, 05 Jan 2007 12:52:19 -0800
> > > > >
> > > > >Michael Ni wrote:
> > > > >>
> > > > >>the web application uses simple queries, like
> > > > search a table for a certain
> > > > >>condition.  i realize when multiple people
> > access
> > > > the database it hangs,
> > > > >>and causes the jsp pages to error.
> > > > >Just a guess, your connection to the database
> > is a
> > > > problem, perhaps errors
> > > > >in queries, not closed connections.
> > > > >What are the error messages? (page/log)
> > > > >
> > > > >--
> > > > >Darek Czarkowski
> > > > >Ph: 604 294 6557 (Ext. 113)
> > > > >Fx: 604 294 6507
> > > > >www.infinitesource.ca
> > > > >darekc at infinitesource dot ca
> > > > >
> > > > >
> > > >
> > >
> >
> >---------------------------------------------------------------------
> > > > >To start a new topic, e-mail:
> > > > users@tomcat.apache.org
> > > > >To unsubscribe, e-mail:
> > > > users-unsubscribe@tomcat.apache.org
> > > > >For additional commands, e-mail:
> > > > users-help@tomcat.apache.org
> > > > >
> > > >
> > > >
> >
> >_________________________________________________________________
> > > > Type your favorite song.  Get a customized
> > station. 
> > > > Try MSN Radio powered
> > > > by Pandora.
> > > > http://radio.msn.com/?icid=T002MSN03A07001
> > > >
> > > >
> > > >
> >
> >---------------------------------------------------------------------
> > > > To start a new topic, e-mail:
> > > > users@tomcat.apache.org
> > > > To unsubscribe, e-mail:
> > > > users-unsubscribe@tomcat.apache.org
> > > > For additional commands, e-mail:
> > > > users-help@tomcat.apache.org
> > > >
> > > >
> > >
> > >
> > >__________________________________________________
> > >Do You Yahoo!?
> > >Tired of spam?  Yahoo! Mail has the best spam
> > protection around
> > >http://mail.yahoo.com
> > >
> >
> >---------------------------------------------------------------------
> > >To start a new topic, e-mail:
> > users@tomcat.apache.org
> > >To unsubscribe, e-mail:
> > users-unsubscribe@tomcat.apache.org
> > >For additional commands, e-mail:
> > users-help@tomcat.apache.org
> > >
> >
> >
>_________________________________________________________________
> > From photos to predictions, The MSN Entertainment
> > Guide to Golden Globes has
> > it all.
> > http://tv.msn.com/tv/globes2007/?icid=nctagline1
> >
> >
> >
>---------------------------------------------------------------------
> > To start a new topic, e-mail:
> > users@tomcat.apache.org
> > To unsubscribe, e-mail:
> > users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail:
> > users-help@tomcat.apache.org
> >
> >
>
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around
>http://mail.yahoo.com
>
>---------------------------------------------------------------------
>To start a new topic, e-mail: users@tomcat.apache.org
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>

_________________________________________________________________
Get FREE Web site and company branded e-mail from Microsoft Office Live 
http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by Caroline Jen <ji...@yahoo.com>.
For configuring a connection pool, follow this URL:
http://jakarta.apache.org/commons/dbcp/configuration.html

1. The JDBC driver JAR must go in the common/lib
directory (because for connection pooling it needs to
be accessible to 
both Tomcat and the web app).

2. DBCP is built into Tomcat so you don't need to
install a JAR for that.

3. Always close the connection when you're done with
it. 

The configuration shown below is what in my Tomcat's
server.xml file:

        <DefaultContext>
	      <Resource name="jdbc/MySQLDB" auth="Container"
		  type="javax.sql.DataSource"/>
	      <ResourceParams name="jdbc/MySQLDB">
                  <parameter>
                        <name>factory</name>
                       
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
                  </parameter>
		  <parameter>
		  	<name>driverClassName</name>
		  	<value>com.mysql.jdbc.Driver</value>
		  </parameter>
		  <parameter>
		   	<name>url</name>
		    
<value>jdbc:mysql://localhost:3306/artimus?autoReconnect=true</value>
		  </parameter>
		  <parameter>
		    	<name>username</name>
		    	<value>javauser</value>
		  </parameter>
		  <parameter>
		    	<name>password</name>
		    	<value>javadude</value>
		  </parameter>
		  <parameter>
		    	<name>maxActive</name>
		    	<value>20</value>
		  </parameter>
		  <parameter>
		    	<name>maxIdle</name>
		    	<value>30</value>
		  </parameter>
		  <parameter>
		    	<name>maxWait</name>
		    	<value>10000</value>
		  </parameter>
                  <parameter>
                        <name>removeAbandoned</name>
                        <value>true</value>
                  </parameter>
                  <parameter>
                       
<name>removeAbandonedTimeout</name>
                        <value>60</value>
                  </parameter>
                  <parameter>
                        <name>logAbandoned</name>
                        <value>true</value>
                  </parameter>

              </ResourceParams>
	</DefaultContext>
    
    </Host>

Then, the code to get a DB connection is:

import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class DBConnection 
{
   public static Connection getDBConnection() throws
SQLException
   {
      Connection conn = null;

      try
      {
         InitialContext ctx = new InitialContext();
         DataSource ds = ( DataSource ) ctx.lookup(
"java:comp/env/jdbc/MySQLDB" );

         try 
         {
            conn = ds.getConnection();
         }
         catch( SQLException e )
         {  
            System.out.println( "Open connection
failure: " + e.getMessage() );
         }
      }
      catch( NamingException nEx )
      {
         nEx.printStackTrace();
      }
      return conn;
   }
}

Then, the code to use the DB connection:

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.artimus.message.ThreadBean;
import org.apache.artimus.message.PostBean;
import org.apache.artimus.message.AttachmentBean;
import
org.apache.artimus.message.exceptions.MessageDAOSysException;
import
org.apache.artimus.message.exceptions.ObjectNotFoundException;
import
org.apache.artimus.message.exceptions.AssertionException;
import
org.apache.artimus.message.exceptions.DatabaseException;
import
org.apache.artimus.message.exceptions.BadInputException;
import org.apache.artimus.ConnectionPool.DBConnection;

public class MySQLMessageDAO implements MessageDAO
{
   public void createThread( String receiver, String
sender, String title, 
                             String
lastPostMemberName, String threadTopic, 
                             String threadBody,
Timestamp threadCreationDate, 
                             Timestamp
threadLastPostDate, int threadType, 
                             int threadOption, int
threadStatus, int threadViewCount, 
                             int threadReplyCount, int
threadDuration )
                             throws
MessageDAOSysException
   {
      Connection conn = null;
      PreparedStatement stmt = null;
      String insertSQL = "INSERT INTO message_thread(
message_receiver, message_sender, article_title,
last_post_member_name, thread_topic, thread_body,
thread_creation_date, thread_last_post_date,
thread_type, thread_option, thread_status,
thread_view_count, thread_reply_count, thread_duration
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

      try
      {
         conn = DBConnection.getDBConnection();
         stmt = conn.prepareStatement( insertSQL );

         stmt.setString( 1, receiver );
         stmt.setString( 2, sender );
         stmt.setString( 3, title );
         stmt.setString( 4, lastPostMemberName );
         stmt.setString( 5, threadTopic );
         stmt.setString( 6, threadBody );
         stmt.setTimestamp( 7, threadCreationDate );
         stmt.setTimestamp( 8, threadLastPostDate );
         stmt.setInt( 9, threadType );
         stmt.setInt( 10, threadOption );
         stmt.setInt( 11, threadStatus );
         stmt.setInt( 12, threadViewCount );
         stmt.setInt( 13, threadReplyCount );
         stmt.setInt( 14, threadDuration );

         stmt.executeUpdate();
         // m_dirty = true;
      }
      catch( SQLException se )
      {
         System.out.println( se.getMessage() );
         se.printStackTrace();
         throw new MessageDAOSysException( "Error
executing SQL in ThreadHandler.createThread." );
      } 
      finally 
      {
         if ( conn != null )
         {
            try
            {
               stmt.close();
               stmt = null;
               conn.close();
            }
            catch( SQLException sqlEx )
            {
               System.out.println( "Problem occurs
while closing " + sqlEx );
            }
            conn = null;
         }       
      }
   }
} 

-Caroline 
--- Michael Ni <mi...@hotmail.com> wrote:

> thx caroline
> 
> 
> >From: Caroline Jen <ji...@yahoo.com>
> >Reply-To: "Tomcat Users List"
> <us...@tomcat.apache.org>
> >To: Tomcat Users List <us...@tomcat.apache.org>
> >Subject: Re: web application - student need help
> >Date: Fri, 5 Jan 2007 13:42:18 -0800 (PST)
> >
> >Did you configure a connection pool in Tomcat? 
> Then,
> >get a connection object from the pool for each data
> >search method invocation.
> >
> >I am at work now.  I do not have the configuration
> >with me.  I can post the configuration and the
> >database access code when I get home.
> >
> >Meanwhile, do a search on the internet.
> >--- Michael Ni <mi...@hotmail.com> wrote:
> >
> > > i don't get any error when there isn't that much
> > > traffic
> > >
> > > but i dont close my jdbc connections, could that
> be
> > > a problem?
> > >
> > > this is the function i use to query
> > >
> > >
>
>----------------------------------------------------------------------------------------
> > > public ResultSet getData(String queryStr) throws
> > > Exception
> > > 	{
> > >
> > > 		try {
> > > 			DBConstants db = new DBConstants();
> > > 			Class.forName(db.getDrivername());
> > > 			Connection conn;
> > > 			conn =
> > >
>
>DriverManager.getConnection("jdbc:microsoft:sqlserver://"
> > > +
> > > db.getHostname() + "","" + db.getUsername() +
> "",""
> > > + db.getPassword() +
> > > "");
> > >
> > >
> > > 			Statement stmt = conn.createStatement();
> > > 			ResultSet rs = stmt.executeQuery(queryStr);
> > > 			return rs;
> > > 		}
> > > 		catch(Exception e) {
> > > 			e.printStackTrace();
> > > 			System.out.println("getData error");
> > > 			throw new Exception();
> > > 		}
> > > 	}
> > >
>
>----------------------------------------------------------------------------------
> > >
> > > then if i want to use it in a jsp page i will do
> > > something like this
> > >
>
>------------------------------------------------------------------------
> > >
> > > <%
> > >   DBPoolBean dbpb = new DBPoolBean();
> > >
> > >   ResultSet rs = dbpb.getData("SELECT * FROM
> drops
> > > order by hnm,
> > > itemname_en");
> > >   while ( rs.next() ) {
> > >     out.println("<tr><td width=\"50\">" +
> > > rs.getString("hnm") + " </td>");
> > >     out.println("<td width=\"50\">" +
> > > rs.getString("itemname_en") + "
> > > </td></tr>");
> > >   }
> > > %>
> > >
> > >
> > >
> > > >From: Darek Czarkowski
> > > <dc...@infinitesource.ca>
> > > >Reply-To: "Tomcat Users List"
> > > <us...@tomcat.apache.org>
> > > >To: Tomcat Users List <us...@tomcat.apache.org>
> > > >Subject: Re: web application - student need
> help
> > > >Date: Fri, 05 Jan 2007 12:52:19 -0800
> > > >
> > > >Michael Ni wrote:
> > > >>
> > > >>the web application uses simple queries, like
> > > search a table for a certain
> > > >>condition.  i realize when multiple people
> access
> > > the database it hangs,
> > > >>and causes the jsp pages to error.
> > > >Just a guess, your connection to the database
> is a
> > > problem, perhaps errors
> > > >in queries, not closed connections.
> > > >What are the error messages? (page/log)
> > > >
> > > >--
> > > >Darek Czarkowski
> > > >Ph: 604 294 6557 (Ext. 113)
> > > >Fx: 604 294 6507
> > > >www.infinitesource.ca
> > > >darekc at infinitesource dot ca
> > > >
> > > >
> > >
> >
>
>---------------------------------------------------------------------
> > > >To start a new topic, e-mail:
> > > users@tomcat.apache.org
> > > >To unsubscribe, e-mail:
> > > users-unsubscribe@tomcat.apache.org
> > > >For additional commands, e-mail:
> > > users-help@tomcat.apache.org
> > > >
> > >
> > >
>
>_________________________________________________________________
> > > Type your favorite song.  Get a customized
> station. 
> > > Try MSN Radio powered
> > > by Pandora.
> > > http://radio.msn.com/?icid=T002MSN03A07001
> > >
> > >
> > >
>
>---------------------------------------------------------------------
> > > To start a new topic, e-mail:
> > > users@tomcat.apache.org
> > > To unsubscribe, e-mail:
> > > users-unsubscribe@tomcat.apache.org
> > > For additional commands, e-mail:
> > > users-help@tomcat.apache.org
> > >
> > >
> >
> >
> >__________________________________________________
> >Do You Yahoo!?
> >Tired of spam?  Yahoo! Mail has the best spam
> protection around
> >http://mail.yahoo.com
> >
>
>---------------------------------------------------------------------
> >To start a new topic, e-mail:
> users@tomcat.apache.org
> >To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> >For additional commands, e-mail:
> users-help@tomcat.apache.org
> >
> 
>
_________________________________________________________________
> From photos to predictions, The MSN Entertainment
> Guide to Golden Globes has 
> it all.
> http://tv.msn.com/tv/globes2007/?icid=nctagline1
> 
> 
>
---------------------------------------------------------------------
> To start a new topic, e-mail:
> users@tomcat.apache.org
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by Michael Ni <mi...@hotmail.com>.
thx caroline


>From: Caroline Jen <ji...@yahoo.com>
>Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
>To: Tomcat Users List <us...@tomcat.apache.org>
>Subject: Re: web application - student need help
>Date: Fri, 5 Jan 2007 13:42:18 -0800 (PST)
>
>Did you configure a connection pool in Tomcat?  Then,
>get a connection object from the pool for each data
>search method invocation.
>
>I am at work now.  I do not have the configuration
>with me.  I can post the configuration and the
>database access code when I get home.
>
>Meanwhile, do a search on the internet.
>--- Michael Ni <mi...@hotmail.com> wrote:
>
> > i don't get any error when there isn't that much
> > traffic
> >
> > but i dont close my jdbc connections, could that be
> > a problem?
> >
> > this is the function i use to query
> >
> >
>----------------------------------------------------------------------------------------
> > public ResultSet getData(String queryStr) throws
> > Exception
> > 	{
> >
> > 		try {
> > 			DBConstants db = new DBConstants();
> > 			Class.forName(db.getDrivername());
> > 			Connection conn;
> > 			conn =
> >
>DriverManager.getConnection("jdbc:microsoft:sqlserver://"
> > +
> > db.getHostname() + "","" + db.getUsername() + "",""
> > + db.getPassword() +
> > "");
> >
> >
> > 			Statement stmt = conn.createStatement();
> > 			ResultSet rs = stmt.executeQuery(queryStr);
> > 			return rs;
> > 		}
> > 		catch(Exception e) {
> > 			e.printStackTrace();
> > 			System.out.println("getData error");
> > 			throw new Exception();
> > 		}
> > 	}
> >
>----------------------------------------------------------------------------------
> >
> > then if i want to use it in a jsp page i will do
> > something like this
> >
>------------------------------------------------------------------------
> >
> > <%
> >   DBPoolBean dbpb = new DBPoolBean();
> >
> >   ResultSet rs = dbpb.getData("SELECT * FROM drops
> > order by hnm,
> > itemname_en");
> >   while ( rs.next() ) {
> >     out.println("<tr><td width=\"50\">" +
> > rs.getString("hnm") + " </td>");
> >     out.println("<td width=\"50\">" +
> > rs.getString("itemname_en") + "
> > </td></tr>");
> >   }
> > %>
> >
> >
> >
> > >From: Darek Czarkowski
> > <dc...@infinitesource.ca>
> > >Reply-To: "Tomcat Users List"
> > <us...@tomcat.apache.org>
> > >To: Tomcat Users List <us...@tomcat.apache.org>
> > >Subject: Re: web application - student need help
> > >Date: Fri, 05 Jan 2007 12:52:19 -0800
> > >
> > >Michael Ni wrote:
> > >>
> > >>the web application uses simple queries, like
> > search a table for a certain
> > >>condition.  i realize when multiple people access
> > the database it hangs,
> > >>and causes the jsp pages to error.
> > >Just a guess, your connection to the database is a
> > problem, perhaps errors
> > >in queries, not closed connections.
> > >What are the error messages? (page/log)
> > >
> > >--
> > >Darek Czarkowski
> > >Ph: 604 294 6557 (Ext. 113)
> > >Fx: 604 294 6507
> > >www.infinitesource.ca
> > >darekc at infinitesource dot ca
> > >
> > >
> >
> >---------------------------------------------------------------------
> > >To start a new topic, e-mail:
> > users@tomcat.apache.org
> > >To unsubscribe, e-mail:
> > users-unsubscribe@tomcat.apache.org
> > >For additional commands, e-mail:
> > users-help@tomcat.apache.org
> > >
> >
> >
>_________________________________________________________________
> > Type your favorite song.  Get a customized station. 
> > Try MSN Radio powered
> > by Pandora.
> > http://radio.msn.com/?icid=T002MSN03A07001
> >
> >
> >
>---------------------------------------------------------------------
> > To start a new topic, e-mail:
> > users@tomcat.apache.org
> > To unsubscribe, e-mail:
> > users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail:
> > users-help@tomcat.apache.org
> >
> >
>
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around
>http://mail.yahoo.com
>
>---------------------------------------------------------------------
>To start a new topic, e-mail: users@tomcat.apache.org
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>

_________________________________________________________________
>From photos to predictions, The MSN Entertainment Guide to Golden Globes has 
it all. http://tv.msn.com/tv/globes2007/?icid=nctagline1


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by Caroline Jen <ji...@yahoo.com>.
Did you configure a connection pool in Tomcat?  Then,
get a connection object from the pool for each data
search method invocation.

I am at work now.  I do not have the configuration
with me.  I can post the configuration and the
database access code when I get home.

Meanwhile, do a search on the internet.
--- Michael Ni <mi...@hotmail.com> wrote:

> i don't get any error when there isn't that much
> traffic
> 
> but i dont close my jdbc connections, could that be
> a problem?
> 
> this is the function i use to query
> 
>
----------------------------------------------------------------------------------------
> public ResultSet getData(String queryStr) throws
> Exception
> 	{
> 
> 		try {
> 			DBConstants db = new DBConstants();
> 			Class.forName(db.getDrivername());
> 			Connection conn;
> 			conn =
>
DriverManager.getConnection("jdbc:microsoft:sqlserver://"
> + 
> db.getHostname() + "","" + db.getUsername() + "",""
> + db.getPassword() + 
> "");
> 
> 
> 			Statement stmt = conn.createStatement();
> 			ResultSet rs = stmt.executeQuery(queryStr);
> 			return rs;
> 		}
> 		catch(Exception e) {
> 			e.printStackTrace();
> 			System.out.println("getData error");
> 			throw new Exception();
> 		}
> 	}
>
----------------------------------------------------------------------------------
> 
> then if i want to use it in a jsp page i will do
> something like this
>
------------------------------------------------------------------------
> 
> <%
>   DBPoolBean dbpb = new DBPoolBean();
> 
>   ResultSet rs = dbpb.getData("SELECT * FROM drops
> order by hnm, 
> itemname_en");
>   while ( rs.next() ) {
>     out.println("<tr><td width=\"50\">" +
> rs.getString("hnm") + " </td>");
>     out.println("<td width=\"50\">" +
> rs.getString("itemname_en") + " 
> </td></tr>");
>   }
> %>
> 
> 
> 
> >From: Darek Czarkowski
> <dc...@infinitesource.ca>
> >Reply-To: "Tomcat Users List"
> <us...@tomcat.apache.org>
> >To: Tomcat Users List <us...@tomcat.apache.org>
> >Subject: Re: web application - student need help
> >Date: Fri, 05 Jan 2007 12:52:19 -0800
> >
> >Michael Ni wrote:
> >>
> >>the web application uses simple queries, like
> search a table for a certain 
> >>condition.  i realize when multiple people access
> the database it hangs, 
> >>and causes the jsp pages to error.
> >Just a guess, your connection to the database is a
> problem, perhaps errors 
> >in queries, not closed connections.
> >What are the error messages? (page/log)
> >
> >--
> >Darek Czarkowski
> >Ph: 604 294 6557 (Ext. 113)
> >Fx: 604 294 6507
> >www.infinitesource.ca
> >darekc at infinitesource dot ca
> >
> >
>
>---------------------------------------------------------------------
> >To start a new topic, e-mail:
> users@tomcat.apache.org
> >To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> >For additional commands, e-mail:
> users-help@tomcat.apache.org
> >
> 
>
_________________________________________________________________
> Type your favorite song.  Get a customized station. 
> Try MSN Radio powered 
> by Pandora.
> http://radio.msn.com/?icid=T002MSN03A07001
> 
> 
>
---------------------------------------------------------------------
> To start a new topic, e-mail:
> users@tomcat.apache.org
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by Michael Ni <mi...@hotmail.com>.
i don't get any error when there isn't that much traffic

but i dont close my jdbc connections, could that be a problem?

this is the function i use to query

----------------------------------------------------------------------------------------
public ResultSet getData(String queryStr) throws Exception
	{

		try {
			DBConstants db = new DBConstants();
			Class.forName(db.getDrivername());
			Connection conn;
			conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://" + 
db.getHostname() + "","" + db.getUsername() + "","" + db.getPassword() + 
"");


			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery(queryStr);
			return rs;
		}
		catch(Exception e) {
			e.printStackTrace();
			System.out.println("getData error");
			throw new Exception();
		}
	}
----------------------------------------------------------------------------------

then if i want to use it in a jsp page i will do something like this
------------------------------------------------------------------------

<%
  DBPoolBean dbpb = new DBPoolBean();

  ResultSet rs = dbpb.getData("SELECT * FROM drops order by hnm, 
itemname_en");
  while ( rs.next() ) {
    out.println("<tr><td width=\"50\">" + rs.getString("hnm") + " </td>");
    out.println("<td width=\"50\">" + rs.getString("itemname_en") + " 
</td></tr>");
  }
%>



>From: Darek Czarkowski <dc...@infinitesource.ca>
>Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
>To: Tomcat Users List <us...@tomcat.apache.org>
>Subject: Re: web application - student need help
>Date: Fri, 05 Jan 2007 12:52:19 -0800
>
>Michael Ni wrote:
>>
>>the web application uses simple queries, like search a table for a certain 
>>condition.  i realize when multiple people access the database it hangs, 
>>and causes the jsp pages to error.
>Just a guess, your connection to the database is a problem, perhaps errors 
>in queries, not closed connections.
>What are the error messages? (page/log)
>
>--
>Darek Czarkowski
>Ph: 604 294 6557 (Ext. 113)
>Fx: 604 294 6507
>www.infinitesource.ca
>darekc at infinitesource dot ca
>
>
>---------------------------------------------------------------------
>To start a new topic, e-mail: users@tomcat.apache.org
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>

_________________________________________________________________
Type your favorite song.  Get a customized station.  Try MSN Radio powered 
by Pandora. http://radio.msn.com/?icid=T002MSN03A07001


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by Darek Czarkowski <dc...@infinitesource.ca>.
Michael Ni wrote:
>
> the web application uses simple queries, like search a table for a 
> certain condition.  i realize when multiple people access the database 
> it hangs, and causes the jsp pages to error.
Just a guess, your connection to the database is a problem, perhaps 
errors in queries, not closed connections.
What are the error messages? (page/log)

-- 
Darek Czarkowski
Ph: 604 294 6557 (Ext. 113)
Fx: 604 294 6507
www.infinitesource.ca
darekc at infinitesource dot ca 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: web application - student need help

Posted by chaitya shah <ch...@gmail.com>.
I think u should use JDBC POOL BEAN concept upto my knowledge after using
this concept it will not hang ur jsp page n by d way wht error it throw??
On 1/8/07, Andre Prasetya <an...@gmail.com> wrote:
>
> When the jsp shows error, its about exception right ? what is the
> exception
> and what does it says ?
>
> On 1/6/07, Michael Ni <mi...@hotmail.com> wrote:
> >
> > Hi i'm doing a web application to help manage players for the online
> game
> > Final Fantasy XI.
> >
> > Im using tomcat, sqlserver2000, and jsp.
> >
> > both sqlserver and tomcat are set up on the same computer.
> > computer is pentium 2.8 GHZ with 512 RAM.
> > im on cable internet
> >
> > the web application uses simple queries, like search a table for a
> certain
> > condition.  i realize when multiple people access the database it hangs,
> > and
> > causes the jsp pages to error.
> >
> > Is it mainly tomcat, or sql server?  anyone have any experience on
> setting
> > up websites to handle a lot of traffic?
> >
> > here is my site project
> > http://66.215.70.71/
> >
> > thx
> > mike
> >
> > _________________________________________________________________
> > Get FREE Web site and company branded e-mail from Microsoft Office Live
> > http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/
> >
> >
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>
>
> --
> -Andre-
>
> People see things the way they are and say "why ?" I see things that never
> were and say "Why not ?"
>
>


-- 
Chaitya Shah

Re: web application - student need help

Posted by Andre Prasetya <an...@gmail.com>.
When the jsp shows error, its about exception right ? what is the exception
and what does it says ?

On 1/6/07, Michael Ni <mi...@hotmail.com> wrote:
>
> Hi i'm doing a web application to help manage players for the online game
> Final Fantasy XI.
>
> Im using tomcat, sqlserver2000, and jsp.
>
> both sqlserver and tomcat are set up on the same computer.
> computer is pentium 2.8 GHZ with 512 RAM.
> im on cable internet
>
> the web application uses simple queries, like search a table for a certain
> condition.  i realize when multiple people access the database it hangs,
> and
> causes the jsp pages to error.
>
> Is it mainly tomcat, or sql server?  anyone have any experience on setting
> up websites to handle a lot of traffic?
>
> here is my site project
> http://66.215.70.71/
>
> thx
> mike
>
> _________________________________________________________________
> Get FREE Web site and company branded e-mail from Microsoft Office Live
> http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
-Andre-

People see things the way they are and say "why ?" I see things that never
were and say "Why not ?"