# Getting at DBI connection via ActiveRecord connection

**URL:** <https://www.ruby-forum.com/t/getting-at-dbi-connection-via-activerecord-connection/154571>\
**Category:** Rails\
**Created:** [December 1, 2008, 6:58pm UTC](https://www.ruby-forum.com/t/getting-at-dbi-connection-via-activerecord-connection/154571 "2008-12-01T18:58:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 1, 2008, 6:58pm UTC](https://www.ruby-forum.com/t/getting-at-dbi-connection-via-activerecord-connection/154571/1 "2008-12-01T18:58:29Z")

</div>

I have a standalone batch program that is going to move data between two  
databases.

I am taking advantage of the AR connection semantics in database.yml to  
get connections to these two DBs. But I want to do all of my DB access  
at the DBI/DBD level for performance reasons.

I am having trouble getting access to the underlying DBI handle so that  
I can prepare SQL statements, execute them etc.

From a connection retrieve via AR::Base.retrieve\_connection, how can I  
get at the DBI handle?

Is it possible that I’ve misunderstood that AR DB access is built on top  
of DBI?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 1, 2008, 7:58pm UTC](https://www.ruby-forum.com/t/getting-at-dbi-connection-via-activerecord-connection/154571/2 "2008-12-01T19:58:06Z")

</div>

Upon further inspection, I see that AR doesn’t depend on DBI. I wonder  
why not…

As it turns out, I’m in a JRuby environment, so I can just do prepared  
statements via that method.

Thanks,  
Wes
