JDBC Questio

A

AC

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?
 
C

Chris Smith

AC said:
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
 
A

AC

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top