|
java.sql |
import java.sql.* |
import java.sql.*; <--- import classes in the JDBC package
public class myJDBCprogram
{
....
public static void main(String[] args) throws SQLException
{
/* ------------------------------------------
These steps are performed ONCE only
to setup the communication
------------------------------------------ */
1. Load the appropriate JDBC communication driver;
Analogy: we install a telephone so we can make calls to mySQL
2. Connect to the database
Analogy: we dial the mySQL server number....
3. Create a SQL Statement object to execute query
Analogy: we get a (erasable) notpad (to save info)
/* -------------------------------------------------------
These steps can be performed any number of times....
------------------------------------------------------- */
4. Submit SQL statement for processing and receive back
a handle (cursor) to receive result
Analogy: we ask a question
5. Retrieve the tuples in the result set (loop !)
Analogy: we write down the answer(s) on the notepad
/* -------------------------------------------------------
These step is done ONCE when we're done
------------------------------------------------------- */
6. Cleanup when program is done.
Analogy: We get rid of the notepad and the telephone !
}
}
|
|