JDBC Tutorial

Connect to Database

The first step in being able to work with a database is to connect to that database. It's a process that's analogous to a web browser making a connection to a web server. The browser makes a connection to a server, sends a specially formatted message to the server, and receives a response back from the server. When working with a database, your code will use the JDBC API to get a connection to a database server, send a specially formatted message to the server, and receive a response back from the server. The JDBC API is an abstraction, and it uses a database-specific code library to communicate with a particular database. When making a database connection, your code does not need to open any sockets, or use any classes of the java.net package to make a connection to the database. All the connection details are handled primarily by a class in the database-specific library. This class is known as driver. Your code simply tells a class known as the Driver Manager that it needs a connection, and the Driver Manager works with the driver to create a connection to the database that your code can use.