JDBC Questio  
Author Message
AC





PostPosted: 2005-2-1 2:21:00 Top

java-programmer, JDBC Questio Coming from the world of VisualBasic, I'm not find Java too hard to catch on
to. After just a couple of weeks of real coding, I'm even cranking out some
code to access a MySQL database. I've got something of a conceptual hill to
jump over, and that's about the Statement class. In VB, I'm used to using
ADO, and just opening a connection and then running queries against it
(either record sets or update-style queries). Is it just the case that any
code I'm translating I just need to insert the lines dealing with the
Statement class, and that's it? What is the purpose of Statement?

--
Aaron Clausen
email***@***.com
 
Chris Smith





PostPosted: 2005-2-1 2:53:00 Top

java-programmer >> JDBC Questio AC <email***@***.com> wrote:
> Coming from the world of VisualBasic, I'm not find Java too hard to catch on
> to. After just a couple of weeks of real coding, I'm even cranking out some
> code to access a MySQL database. I've got something of a conceptual hill to
> jump over, and that's about the Statement class. In VB, I'm used to using
> ADO, and just opening a connection and then running queries against it
> (either record sets or update-style queries). Is it just the case that any
> code I'm translating I just need to insert the lines dealing with the
> Statement class, and that's it? What is the purpose of Statement?

There are several ways to interact with SQL. They are:

1. Just run queries.

2. Call stored procedures (except that you're using MySQL, which is one
of the very few major databases that don't provide this feature).

3. Use server-prepared statements and then plug in parameters where they
are needed.

If you're using the first approach, then yes you just need to call
createStatement and get on your way. In that case, the extra layer of
having a statement might seem pointless.

However, when you're doing either of the last two, there can sometimes
be substantial advantages to "getting ready" to do things only once, and
then actually interacting with the database several times, passing
different parameters each time. Whether the database takes advantage of
this is implementation specific -- for example, PostgreSQL didn't up
until the drivers from version 8.0; but now it does. The point is that
JDBC is a generic interface, and it's designed so that you can write
code that *will* run faster if the database and drivers support it.

There are also other details to the Statement class, but that's the bulk
of it.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
AC





PostPosted: 2005-2-2 2:05:00 Top

java-programmer >> JDBC Questio On Mon, 31 Jan 2005 11:53:01 -0700,
Chris Smith <email***@***.com> wrote:
>
> There are also other details to the Statement class, but that's the bulk
> of it.
>

Thanks for the details, that helps considerably. Just trying to wrap my
brain around this.

--
Aaron Clausen
email***@***.com