473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with Database while using JNDI Lookup.

dmjpro
2,476 2GB
I thought that when the connection gets closed then all resources get closed .
I also included the ResultSet and Statement ;) . But if the Statement closed then only ResultSet closed. But now i got the point ..after closing Connection i am still able to access to iterate the ResultSet . Actually it is tested only with Postgres. Is it sun specified : ?

Now i tested another code ...
Expand|Select|Wrap|Line Numbers
  1. import org.apache.tomcat.dbcp.dbcp.cpdsadapter.DriverAdapterCPDS;
  2. import org.apache.tomcat.dbcp.dbcp.datasources.SharedPoolDataSource;
  3.  
  4.         DriverAdapterCPDS l_adapter = new DriverAdapterCPDS();
  5.         l_adapter.setDriver("org.postgresql.Driver");
  6.         l_adapter.setUrl("jdbc:postgresql://10.29.32.68:5432/Admin");
  7.         l_adapter.setUser("erp");
  8.         l_adapter.setPassword("iiterp");
  9.  
  10.         SharedPoolDataSource l_ds = new SharedPoolDataSource();
  11.         l_ds.setConnectionPoolDataSource(l_adapter);
  12.         Connection l_con = l_ds.getConnection();
  13.  
  14.         Statement l_stmt = l_con.createStatement();
  15.         ResultSet l_rs = l_stmt.executeQuery("select * from dpcode");
  16.         l_con.close();
  17.         while(l_rs.next()){System.out.println("Yahoo!!!");}
  18.  
The Resultset is still getting iterated ...

But when I get the DataSource using the JNDI look up then my another code is not working ..Saying that the ResultSet is closed.
Could you help me to figure out ...
Expand|Select|Wrap|Line Numbers
  1.             Context l_ctx = new InitialContext();
  2.             DataSource l_ds =                     (DataSource)l_ctx.lookup("java:/comp/env/jdbc/admindatasource");
  3.             Connection l_con = l_ds.getConnection();
  4.  
  5.             Statement l_stmt = l_con.createStatement();
  6.             ResultSet l_rs = l_stmt.executeQuery("select * from dpcode");
  7.             l_con.close();
  8.             while(l_rs.next()){System.out.println("Yahoo!!!");}
  9.  
Please help me to figure out .. ;)
Jan 21 '09 #1
9 2636
JosAH
11,448 Expert 8TB
A Connection is the owner of a Statement. A Statement is the owner of a ResultSet. When you close an object earlier in the chain the other objects, later in the chain, are also closed. A PooledConnection isn't closed when you get rid of it, i.e. it is simply returned to its pool. Read the API documentation for the close() method of a Connection: "If the close method is called and there is an active transaction, the results are implementation-defined. "

kind regards,

Jos
Jan 21 '09 #2
dmjpro
2,476 2GB
Then why does it happen to me ???
U mean that whats are happening that should not be ?
I could not get you ..yeah i know .when a connection(obtained from pool) closed then it simply goes to Pool and be reused later.
But these things are happening to me ?
Jan 21 '09 #3
JosAH
11,448 Expert 8TB
What part of "implementation-defined" was so difficult to understand? You're closing an object earlier in the chain: a Connection; nothing can be said about a Statement or ResultSet. The Connection could just be dumped in a pool again or it may be really closed.

kind regards,

Jos
Jan 21 '09 #4
dmjpro
2,476 2GB
Yeah all these things are implementation dependent ... But still there should be a standard logic to implement ....
Jan 21 '09 #5
r035198x
13,262 8TB
@dmjpro
Yes there is. Close the rs first, then the statement and then the connection.
Jan 21 '09 #6
dmjpro
2,476 2GB
Then why does it behave like a hell ???
Yeah i know ... i should close those resources sequentially ... But the code already developed .. it requires a lot of hurdle ...
That's why i was asking .. if make a raw connection and even also using a DataSource it working fine .. but if i get the DataBase using JNDI look up then it's not working .. i was looking for this answer ?
Jan 21 '09 #7
JosAH
11,448 Expert 8TB
@dmjpro
Because the code assumed a particular implementation defined behaviour; that's an error; e.g. in C and C++ you have to stay far away from "undefined behaviour" and "implementation defined behaviour". Same here: there's an error in the code; fix it and don't ask why anymore.

kind regards,

Jos
Jan 21 '09 #8
dmjpro
2,476 2GB
Don't get me wrong .......... According to the answer of r0... i asked why does this ... anyway the designed was wrong ;)
Jan 21 '09 #9
JosAH
11,448 Expert 8TB
@dmjpro
Erm, yes, that's what I was trying to tell you all the time in replies #2, #4 and #8, but glad you understand it now.

kind regards,

Jos
Jan 21 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mdh | last post by:
I am trying to learn the basics of MVC applications using a Tomcat infrastructure. I'm starting by building a simple application with: * a login.jsp page for a basic login form with a action...
0
by: Arun | last post by:
Hi I am using the following Tomcat: 4.1.27-LE-jdk14 Apache: 2.0.47 Java : 1.4.2 Linux OS: 7.3 I am trying to configure LDAP authentication mechanism to my
1
by: Bridget Willey | last post by:
I am using ACT 6 and am trying to "split" the database between records for customers and junk records. The accounts designated as "customers" have that word in the ID field, and I am using that...
2
by: David | last post by:
Sent this to alt.php a couple of days back, but doesn't look like I'll get an answer, so trying here. I'm trying to convert a script to use friendly URLs, I've done this before, but my PHP...
1
by: sajithamol | last post by:
What’s the difference between JNDI lookup(), list(), listBindings(), and search()?
3
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table:...
10
dmjpro
by: dmjpro | last post by:
My context.xml... <Context path="/JNDITest"> <Resource name="jdbc/dataSource" auth="Container" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"...
0
dmjpro
by: dmjpro | last post by:
When i do .... HashMap props = new HashMap(); props.put(Context.INITIAL_CONTEXT_FACTORY,"FactoryClass"); Context ctx = new InitialContext(props); Here it is obvious that the proper...
1
by: webster5u | last post by:
Hi, who's has experience to open connection pool in Tomcat 5.5 using JNDI? I recently research on it, i found the how-to guideline provided from apache tomcat website. It seem like not really work...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.