Simple demo of accessing DB using JNDI.
How to get the connection?
1. get context;
2. lookup for datasource config;
3. get connection from this datasource;
How to execute SQL?
1. declear SQL String;
2. transform sql into statment on the connection we have got;
3. execute the statement to get the result set;
How to fetch my target field from the result set?
1. for each of the result item;
2. getData(“fieldName”);
Finally, don’t forget to do close the connection, if necessary.
Where is the source code?
please refer to http://www.kodejava.org/examples/131.html
Questions:
When does the connection established?
At the same time with the program starts.