12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package testDM;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import javax.sql.DataSource;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- public class TestDm{
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
- DataSource dataSource = ctx.getBean("dataSource", DataSource.class);
- String sql = "select * from sys_user_info";
- Connection conn = null;
- Statement stm = null;
- ResultSet rs = null;
- try {
- conn = dataSource.getConnection();
- stm = conn.createStatement();
- rs = stm.executeQuery(sql);
- while (rs.next()) {
- System.out.println("用户名为:");
- System.out.println(rs.getString("LOGIN_NAME"));
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- rs.close();
- stm.close();
- conn.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
|