View RSS Feed

Java Database

JDBC Introduction

Rate this Entry
by , 03-10-2012 at 08:36 AM (795 Views)
JDBC API being a java base API, it accesses stored data and tabular data present in relational database. Java applications are written by the help of JDBC API. They are helpful to manage these programming activities, given below:
  • To a data source, connect like a database
  • Send updated statements & database queries.
  • Bring records of database & do processing of these records that have been received from the database.

The given code details the above 3 steps.
Java Code:
public void connectToAndQueryDatabase(
    String username, String password) {

    Connection con = DriverManager.getConnection(
        "jdbc:myDriver:myDatabase", username,

    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(
        "SELECT a, b, c FROM Table1");
    while ( {
        int x = rs.getInt("a");
        String s = rs.getString("b");
        float f = rs.getFloat("c");

Submit "JDBC Introduction" to Facebook Submit "JDBC Introduction" to Digg Submit "JDBC Introduction" to Submit "JDBC Introduction" to StumbleUpon Submit "JDBC Introduction" to Google