美文网首页
数据库连接池__调试

数据库连接池__调试

作者: 枇杷树8824 | 来源:发表于2016-12-17 16:23 被阅读19次

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();

                        }

           }

      }

}

}

相关文章

网友评论

      本文标题:数据库连接池__调试

      本文链接:https://www.haomeiwen.com/subject/ahaomttx.html