• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Database connectivity-Context.xml

 
Ranch Hand
Posts: 49
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried database connectivity using context.xml.
The problem is it takes loading the page continuously for database insertion.
is there any additional parameters to be passed in context.xml

please suggest its urgent

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/sys">
Context.xml file
<Resource name="jdbc/myAPP"
auth="Container"
type="javax.sql.DataSource"
username="sa"
password="sa"
driverClassName="sun.jdbc.odbc.JdbcOdbcDriver"
url="Jdbc:Odbc:testing"
removeAbandoned = "true"
maxActive="10000"
maxIdle="30"
maxWait="10000"
removeAbandonedTimeout="300"
logAbandoned="true"
/>
</Context>

web.xml
.
.
.
<resource-ref>
<description>DB Connection Pool</description>
<res-ref-name>jdbc/myAPP</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mariya Antony christopher wrote:I have tried database connectivity using context.xml.
The problem is it takes loading the page continuously for database insertion.
is there any additional parameters to be passed in context.xml



I don't understand what you mean by "It takes loading the page continuously for database insertion". You have to keep reloading the page for successive queries to work? If you are seeing some database records inserted, that is not a connection issue. Would you share your code so we can better understand what is going on?
 
Mariya Antony christopher
Ranch Hand
Posts: 49
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim McGuire wrote:

Mariya Antony christopher wrote:I have tried database connectivity using context.xml.
The problem is it takes loading the page continuously for database insertion.
is there any additional parameters to be passed in context.xml



I don't understand what you mean by "It takes loading the page continuously for database insertion". You have to keep reloading the page for successive queries to work? If you are seeing some database records inserted, that is not a connection issue. Would you share your code so we can better understand what is going on?



 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My first comment is please read this FAQ SQL column lists
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim McGuire wrote:

Mariya Antony christopher wrote:I have tried database connectivity using context.xml.
The problem is it takes loading the page continuously for database insertion.
is there any additional parameters to be passed in context.xml



I don't understand what you mean by "It takes loading the page continuously for database insertion". You have to keep reloading the page for successive queries to work? If you are seeing some database records inserted, that is not a connection issue. Would you share your code so we can better understand what is going on?



I am sorry but like Tim, I don't understand what your actual problem is?
is it throwing an exception?
is the update statement taking a very long time?
are you having to refresh the page many times?
 
Mariya Antony christopher
Ranch Hand
Posts: 49
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wendy Gibbons wrote:

Tim McGuire wrote:

Mariya Antony christopher wrote:I have tried database connectivity using context.xml.
The problem is it takes loading the page continuously for database insertion.
is there any additional parameters to be passed in context.xml



I don't understand what you mean by "It takes loading the page continuously for database insertion". You have to keep reloading the page for successive queries to work? If you are seeing some database records inserted, that is not a connection issue. Would you share your code so we can better understand what is going on?



I am sorry but like Tim, I don't understand what your actual problem is?
is it throwing an exception?
is the update statement taking a very long time?
are you having to refresh the page many times?




takes long time for database insertion
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mariya Antony christopher wrote:
takes long time for database insertion



and this wasn't a problem when you created the connection in this class as you have commented out here?
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have no code for closing the connection and no try block, which makes me think this isn't your real working code?

If you are not closing the connection in a finally block, this could be gumming up your database.
 
Mariya Antony christopher
Ranch Hand
Posts: 49
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim McGuire wrote:you have no code for closing the connection and no try block, which makes me think this isn't your real working code?

If you are not closing the connection in a finally block, this could be gumming up your database.



Here i have tried code as per your suggestions
whether we have close the Statement,ResultSet in finally block.
The following code will not takes a long time for database insertion

Kindly suggest your comments

Connection ch=null;
try
{
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myAPP");
if(ctx == null )
throw new Exception("No Context");
ch=ds.getConnection();
Statement s=ch.createStatement();
String ab=a+"%";
String q1="select username from issue.login where username like '"+ab+"'";
ResultSet rs=s.executeQuery(q1);
%>
<%
while(rs.next())
{
String kl=rs.getString(1);
//String gh[]=kl.split(" ");
countries[top]=kl;
%>
<%
out.println(countries[top]);
top++;
}
%>
<%
}
catch(Exception e)
{
out.println(e);
}
finally
{
ch.close();

}
%>


 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you doing this inside a jsp file?
I was just wondering what all the <% %> are for?
 
Mariya Antony christopher
Ranch Hand
Posts: 49
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wendy Gibbons wrote:are you doing this inside a jsp file?
I was just wondering what all the <% %> are for?


yes in JSP file only,any issues regarding using jsp file
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mariya Antony christopher wrote:

Wendy Gibbons wrote:are you doing this inside a jsp file?
I was just wondering what all the <% %> are for?


yes in JSP file only,any issues regarding using jsp file



There are many reasons not to do such things inside a jsp:
  • Readability. Use JSTL tags in the view. Keep the java code on the server side.
  • Separation of Concerns - you should not mix presentation logic and business logic
  • Reusability - are you going to write this same code over again for the subsequent .jsps you write?
  • Maintainability - a database column changes and you will be hunting through all your jsps for places to change. better to do this on server side
  • Breaks OOP - you cannot extend what you have done in a jsp
  • Getting business logic out of jsp lets you take advantage of the java bean paradigm
  • finally, due to the above, scriptlets (java code inside of jsp) are used today as a warning sign that a developer does not know what they are doing

  •  
    Wendy L Gibbons
    Bartender
    Posts: 1111
    Eclipse IDE Oracle VI Editor
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Tim McGuire wrote:

    Mariya Antony christopher wrote:

    Wendy Gibbons wrote:are you doing this inside a jsp file?
    I was just wondering what all the <% %> are for?


    yes in JSP file only,any issues regarding using jsp file



    There are many reasons not to do such things inside a jsp:
  • Readability. Use JSTL tags in the view. Keep the java code on the server side.
  • Separation of Concerns - you should not mix presentation logic and business logic
  • Reusability - are you going to write this same code over again for the subsequent .jsps you write?
  • Maintainability - a database column changes and you will be hunting through all your jsps for places to change. better to do this on server side
  • Breaks OOP - you cannot extend what you have done in a jsp
  • Getting business logic out of jsp lets you take advantage of the java bean paradigm
  • finally, due to the above, scriptlets (java code inside of jsp) are used today as a warning sign that a developer does not know what they are doing



  • This is the perfect answer.
     
    Mariya Antony christopher
    Ranch Hand
    Posts: 49
    Hibernate Tomcat Server Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Tim McGuire wrote:

    Mariya Antony christopher wrote:

    Wendy Gibbons wrote:are you doing this inside a jsp file?
    I was just wondering what all the <% %> are for?


    yes in JSP file only,any issues regarding using jsp file



    There are many reasons not to do such things inside a jsp:
  • Readability. Use JSTL tags in the view. Keep the java code on the server side.
  • Separation of Concerns - you should not mix presentation logic and business logic
  • Reusability - are you going to write this same code over again for the subsequent .jsps you write?
  • Maintainability - a database column changes and you will be hunting through all your jsps for places to change. better to do this on server side
  • Breaks OOP - you cannot extend what you have done in a jsp
  • Getting business logic out of jsp lets you take advantage of the java bean paradigm
  • finally, due to the above, scriptlets (java code inside of jsp) are used today as a warning sign that a developer does not know what they are doing




  • Thanks for your suggestions.
    i will implement your suggestion in my further development
     
    reply
      Bookmark Topic Watch Topic
    • New Topic