Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Apache Tomcat »

Re: web application - student need help

Michael Ni

2007-01-05

Replies:

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 <dczarkowski@(protected)>
>Reply-To: "Tomcat Users List" <users@(protected)>
>To: Tomcat Users List <users@(protected)>
>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@(protected)
>To unsubscribe, e-mail: users-unsubscribe@(protected)
>For additional commands, e-mail: users-help@(protected)
>

_________________________________________________________________
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@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.