| Author |
Database connectivity-Context.xml
|
Mariya Antony christopher
Ranch Hand
Joined: Jan 24, 2012
Posts: 49
|
|
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>
|
 |
Tim McGuire
Ranch Hand
Joined: Apr 30, 2003
Posts: 819
|
|
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
Joined: Jan 24, 2012
Posts: 49
|
|
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?
|
 |
Wendy Gibbons
Bartender
Joined: Oct 21, 2008
Posts: 1098
|
|
|
My first comment is please read this FAQ SQL column lists
|
 |
Wendy Gibbons
Bartender
Joined: Oct 21, 2008
Posts: 1098
|
|
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
Joined: Jan 24, 2012
Posts: 49
|
|
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
Joined: Apr 30, 2003
Posts: 819
|
|
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
Joined: Apr 30, 2003
Posts: 819
|
|
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
Joined: Jan 24, 2012
Posts: 49
|
|
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 Gibbons
Bartender
Joined: Oct 21, 2008
Posts: 1098
|
|
are you doing this inside a jsp file?
I was just wondering what all the <% %> are for?
|
 |
Mariya Antony christopher
Ranch Hand
Joined: Jan 24, 2012
Posts: 49
|
|
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
Joined: Apr 30, 2003
Posts: 819
|
|
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 logicReusability - 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 sideBreaks OOP - you cannot extend what you have done in a jspGetting business logic out of jsp lets you take advantage of the java bean paradigmfinally, 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 Gibbons
Bartender
Joined: Oct 21, 2008
Posts: 1098
|
|
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 logicReusability - 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 sideBreaks OOP - you cannot extend what you have done in a jspGetting business logic out of jsp lets you take advantage of the java bean paradigmfinally, 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
Joined: Jan 24, 2012
Posts: 49
|
|
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 logicReusability - 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 sideBreaks OOP - you cannot extend what you have done in a jspGetting business logic out of jsp lets you take advantage of the java bean paradigmfinally, 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
|
 |
 |
|
|
subject: Database connectivity-Context.xml
|
|
|