CHAPTER 5 Using JDBC with Java Applications and
CHAPTER 5 Using JDBC with Java Applications and Applets Now that we have a development environment put together, it s time to start writing Java code that will allow access to a MySQL database using the Connector/J JDBC driver. In the remaining chapters of this blog, it is our goal to exercise as much of the functionality found in the driver as possible. This chapter covers the basics of instantiating the driver, connecting to the database from Java, executing queries, and handling results. From a Java perspective, we look at doing all of these tasks from both applications and applets utilizing various GUI components to deal with the information transfer from the user to the database and from the database to the user. Hello World For the sake of tradition, the first application we build is Hello World. The code in Listing 5.1 creates a Java application and pulls information from a MySQL database. package mysql; import java.sql.*; public class Hello { Connection connection; Listing 5.1 Hello World. (continues) 67
Hint: If you are looking for very good and affordable webspace to host and run your tomcat hosting application check Sandzak.com tomcat web hosting provider