• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Connection Pooling : Does anybody have connection pooling code in jsp?

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am using Tomcat 5.0.27, MySQL 4.0, Apache 2.0

I have configured the settings in server.xml and web.xml. Where do I go from here? What do I do to start using the connection pooling.

Please help me out ranchers...
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://tomcat.apache.org/tomcat-4.1-doc/jndi-datasource-examples-howto.html
 
Nina Savannah
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I have seen the guiding info. However I am not sure how to come up with a full code that actually implements the connection pooling. I would be ALL SMILES if you could give a running jsp code or should I paste the code that I already have even though its not working?
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nina Savannah wrote: I would be ALL SMILES if you could give a running jsp code


I think this post on this forum is your code for connection pooling, am I right ?

Then I suggest, why you are using JSP for defining classes , accessing connection object, its not what recommended i.e java code in JSP. So make class or a servlet which contain all the logic to deal with database ( a pure java code) and forward the result to JSP page to show/display ..

Nina Savannah wrote:or should I paste the code that I already have even though its not working?


Not that JSP code again

I want you to follow this basic setup I provided with that tomcat link. If you faced any problem, post that here..
 
Nina Savannah
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
lol...thanks. I'll work on the info that you have provided and then get back to you with my attempt.
 
Nina Savannah
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have done the configurations but I am now stuck at the end.

My system is located at $CATALINA_HOME/webapps/ROOT/publications
I have saved test.jsp in $CATALINA_HOME/webapps/ROOT/publications

I have saved publications.war in $CATALINA_HOME/webapps/

and I have edit the code as follows:



I wasnt so sure of how to save a war file so I opened a new jsp page in macromedia then pasted the code gave at a .war extension when I was saving it.


When I run http://localhost:8080/publications/test.jsp i get the the following errors:-

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 7 in the jsp file: /publications/test.jsp
Generated servlet error:
foo.publications cannot be resolved or is not a type

An error occurred at line: 7 in the jsp file: /publications/test.jsp
Generated servlet error:
foo.publications cannot be resolved or is not a type


Now I dont know how to correct this.... :roll:

[ARG : added code tags]
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nina Savannah wrote:I have done the configurations but I am now stuck at the end.

My system is located at $CATALINA_HOME/webapps/ROOT/publications
I have saved test.jsp in $CATALINA_HOME/webapps/ROOT/publications


Do NOT put anything in the ROOT folder, just create your own web app folder, "publications" inside /webapps directory

Nina Savannah wrote:
I have saved publications.war in $CATALINA_HOME/webapps/


OK

Nina Savannah wrote:
and I have edit the code as follows:

****TEST.JSP****

<html>
<head>
<title>publications</title>
</head>
<body>

<% out.print("HELLO!!!");
foo.publications tst = new foo.publications();
tst.init();
%>

<h2>Results</h2>
Foo <%= tst.getFoo() %>

Bar <%= tst.getBar() %>

</body>
</html>



****publications.war****


package foo;

import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class publications {

String foo = "Not Connected";
int bar = -1;

public void init() {
try{
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");

DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/publications");

if (ds != null) {
Connection conn = ds.getConnection();

if(conn != null)
{
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst =
stmt.executeQuery(
"select school_code, school_name, bar from out_school");
if(rst.next()) {
foo=rst.getString(2);
bar=rst.getInt(3);
}
conn.close();
}
}
}catch(Exception e) {
e.printStackTrace();
}
}

public String getFoo() { return foo; }
public int getBar() { return bar;}
}


This class should be inside WEB-INF\classes\

Nina Savannah wrote:
I wasnt so sure of how to save a war file so I opened a new jsp page in macromedia then pasted the code gave at a .war extension when I was saving it.


NO, that's not how .war file is build, its like zip file and unzipped by servlet container.

Nina Savannah wrote:
When I run http://localhost:8080/publications/test.jsp i get the the following errors:-

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 7 in the jsp file: /publications/test.jsp
Generated servlet error:
foo.publications cannot be resolved or is not a type

An error occurred at line: 7 in the jsp file: /publications/test.jsp
Generated servlet error:
foo.publications cannot be resolved or is not a type


Now I dont know how to correct this.... :roll:



import package into a JSP page.

After all this clarification I think you need a simple JSP/Servlet tutorial which taught a step by step procedure to build and run web app. http://www.roseindia.net/jsp/ OR look at JSP/Servlet FAQ on this site.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please make sure you use code tags while posting your code.Unformatted code is difficult to read and results in less response for your post. Read this for more information. You can edit your current post to add code tags by clicking button.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sagar Rohankar wrote:
After all this clarification I think you need a simple JSP/Servlet tutorial which taught a step by step procedure to build and run web app. http://www.roseindia.net/jsp/ OR look at JSP/Servlet FAQ on this site.


If you're new to Java EE, do certainly NOT use roseindia.net.
Read this: http://balusc.blogspot.com/2008/06/what-is-it-with-roseindia.html
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bauke Scholtz wrote:

Sagar Rohankar wrote:
After all this clarification I think you need a simple JSP/Servlet tutorial which taught a step by step procedure to build and run web app. http://www.roseindia.net/jsp/ OR look at JSP/Servlet FAQ on this site.


If you're new to Java EE, do certainly NOT use roseindia.net.
Read this: http://balusc.blogspot.com/2008/06/what-is-it-with-roseindia.html



Ooch, that's hell . I think the best resource is to start with is Sun's tutorial..
 
Nina Savannah
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much guys. Looks like I am getting some where. I have started on the JSP tutorials, thanks.

Before I proceed I would like to clarify one thing. Once I have done the settings in web.xml and server.xml, is that all there is for Connection Pooling or am I supposed to write a jsp code that implements the Connection Pooling?

Also, what is the right way to save a war file? Do I need special software for this?
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nina Savannah wrote:
Before I proceed I would like to clarify one thing. Once I have done the settings in web.xml and server.xml, is that all there is for Connection Pooling or am I supposed to write a jsp code that implements the Connection Pooling?



Why you stuck to JSP for your database connection , why don't you, at least, define a simple Servlet and do whatever database coding you want there..

Nina Savannah wrote:
Also, what is the right way to save a war file? Do I need special software for this?



Yes and No, both, If you are well aware about How the basic folder and file configuration are there in .war file, no problem but I don't suppose you should messed up with those folder structure right now, . About s/w , Yes you can have Eclipse/Netbeans, which take care of all that difficulties, like setting CLASSPATH, tomcat server, and of course building a valid .war file..
 
Nina Savannah
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this code here for database connection and its working well. I am not very familiar with servlets so for now i am coding in jsp. My concern then is how can I make the actual connection pooling work? As long as I am connecting to my database well, does that mean that my connection pooling is also working?

I got the impression that I need a code that implements the actual Connection Pooling from here:
Connection Pooling

Here is my Database Connection File:



 
Nina Savannah
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
:roll: Just wondering on the above...i'm confused.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, If you still want to make it through JSP, fine.. I gave up..

Now look at your JSP code, it's contain three getConnection statement , why ? :roll: A single call is enough to get connection object !!

So it looks like, If corrected,






 
Nina Savannah
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, would you mind helping me do the servlets. Please dont give up on me.

What should I do? How do I go about it?
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you should first learn the basic things of servlet like the life cycle method, how to configure url-mappings in web.xml to invoke servlets etc.
 
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic