数据库连接池__调试

2016-12-17  本文已影响19人  枇杷树8824

public class TestMyConnection {

              @Test

               public void testInsert(){

                               Connection conn=null;

                               PreparedStatement pstmt=null;

                   try {

                           DataSource ds=new MyDataSource();

                           //从连接池中取  连接

                            conn=ds.getConnection();

                            System.out.println(conn.getClass().getName());

                  } catch (Exception e) {

                          throw new RuntimeException(e);

                }finally{

               if(null!=conn){

                         try {

                                      conn.close();//释放连接

                         } catch (Exception e2) {

                                     e2.printStackTrace();

                        }

           }

      }

}

}

上一篇 下一篇

猜你喜欢

热点阅读