View RSS Feed

Java Database

JDBC Introduction

Rate this Entry
by , 03-10-2012 at 07:36 AM (732 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,
        password);

    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(
        "SELECT a, b, c FROM Table1");
    while (rs.next()) {
        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 del.icio.us Submit "JDBC Introduction" to StumbleUpon Submit "JDBC Introduction" to Google

Categories
JDBC

Comments