JAVA Database Connectivity (JDBC)
JAVA Database Connectivity (JDBC)
JAVA Database Connectivity (JDBC)
JavaSoft's JDBC consists of two layers: the JDBC API and the
JDBC Driver Manager API.
The JDBC API is the top layer and is the programming interface in
Java to structured query language (SQL) which is the standard for
accessing relational databases.
JDBC/ Vendor-
ODBC supplied
Bridge JDBC
driver
ODBC
driver
Database Database
For those databases that do not have a JDBC driver, you need to
install the database's ODBC driver (available for most
databases) and the JDBC to ODBC bridge supplied by JavaSoft.
import java.net.*;
import java.sql.*; //needed for JDBC
import java.io.*;
class MakeDB {
public static void main (String args[]) {
try {
//load the driver needed by the application
Class.forName("specialdb.Driver");
//Construct the database address
String dbaseURL = "jdbc:mysubprotocol://dbasehost/dbasename";
//Make the database connection
Connection dbConnection =
DriverManager.getConnection(dbaseURL, "dbaseuser", "dbasepasswd");
//Create a statement and execute the SQL query
Statement query = dbConnection.getStatement();
ResultSet results =
query.executeQuery("SELECT first_name, last_name from user_table);