Using JNDI connecting DB

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.

原文地址:https://www.cnblogs.com/alipayhutu/p/2316659.html