Retrieving Column Values with getXXX() Methods

This section describes how to use getXXX() methods to retrieve column values from ResultSet objects.

Once you have moved the cursor to a data row in a ResultSet object, you can use one of the getXXX() methods to retrieve the value of a given column. All getXXX() methods support two types of parameters to specify a column:

JDBC supports many getXXX() methods, one for each Java data type, so that you can retrieve column values right into the desired Java data types without any further conversion. Here is a list of getXXX() methods:

The following sample Java program shows you how to use different getXXX() methods to retrieve column values in different data types:

 * Copyright (c) All Rights Reserved.
import java.sql.*;
public class DerbyGetMethods {
  public static void main(String [] args) {
    Connection con = null;
    try {
      con = DriverManager.getConnection("jdbc:derby://localhost/TestDB");
      Statement sta = con.createStatement();

// getting the data back
      ResultSet res = sta.executeQuery("SELECT * FROM Profile");
      System.out.println("List of Profiles: ");
      while ( {
         int id = res.getInt("ID");
         String firstName = res.getString("FirstName");
         String lastName = res.getString("LastName");
         float points = res.getFloat("Point");
         Date birthDate = res.getDate("BirthDate");
         Timestamp modTime = res.getTimestamp("ModTime");
           "  "+id
           + ", "+firstName
           + ", "+lastName
           + ", "+points
           + ", "+birthDate
           + ", "+modTime);

    } catch (Exception e) {
      System.err.println("Exception: "+e.getMessage());

Here is the output:

List of Profiles:
  2, Janet, Gates, 999.99, 2004-10-13, 2016-12-31 23:59:59.999
  4, 256d, aa3f5, 203.51392, 1999-12-31, 2016-12-31 23:59:59.999
  6, 8ef, 466ca, 31.71128, 1999-12-31, 2016-12-31 23:59:59.999
  8, 10cc, ab361, 325.30505, 1999-12-31, 2017-04-01 23:59:59.999
  9, 11bd, 99552, 315.1111, 1999-12-31, 2017-04-01 23:59:59.999
  10, 8c4, 68909, 23.095905, 1999-12-31, 2017-04-01 23:59:59.999
  11, 17e1, 99a5d, 186.09494, 1999-12-31, 2017-04-01 23:59:59.999
  12, 1ea2, 480c7, 131.6408, 1999-12-31, 2017-04-01 23:59:59.999
  13, Keith, Harris, 0.0, 2010-03-01, 2017-04-01 23:59:59.999

Table of Contents

 About This Book

 JDBC (Java Database Connectivity) Introduction

 JDK (Java SE) Installation

 Installing and Running Java DB - Derby

 Derby (Java DB) JDBC Driver

 Derby (Java DB) JDBC DataSource Objects

 Java DB (Derby) - DML Statements

Java DB (Derby) - ResultSet Objects of Queries

 What Is ResultSet?

 ResultSet Cursor and Scrollability

 ResultSet Cursor Initial Position: Before First Row

Retrieving Column Values with getXXX() Methods

 ResultSet Default Type: Forward-only

 Scrollable ResultSet and Moving Cursor Backward

 ResultSet Objects with Update Capability

 insertRow() - Inserting New Rows through ResultSet Objects

 updateXXX() - Updating Column Values for Row Update or Insert

 deleteRow() - Deleting Rows through ResultSet Objects

 Java DB (Derby) - PreparedStatement

 MySQL Installation on Windows

 MySQL JDBC Driver (MySQL Connector/J)

 MySQL - PreparedStatement

 MySQL - Reference Implementation of JdbcRowSet

 MySQL - JBDC CallableStatement

 MySQL CLOB (Character Large Object) - TEXT

 MySQL BLOB (Binary Large Object) - BLOB

 Oracle Express Edition Installation on Windows

 Oracle JDBC Drivers

 Oracle - Reference Implementation of JdbcRowSet

 Oracle - PreparedStatement

 Oracle - JBDC CallableStatement

 Oracle CLOB (Character Large Object) - TEXT

 Oracle BLOB (Binary Large Object) - BLOB

 Microsoft SQL Server Express Edition

 Microsoft JDBC Driver for SQL Server

 Microsoft JDBC Driver - Query Statements and Result Sets

 Microsoft JDBC Driver - DatabaseMetaData Object

 Microsoft JDBC Driver - DDL Statements

 Microsoft JDBC Driver - DML Statements

 SQL Server - PreparedStatement

 SQL Server CLOB (Character Large Object) - TEXT

 SQL Server BLOB (Binary Large Object) - BLOB

 JDBC-ODBC Bridge Driver - sun.jdbc.odbc.JdbcOdbcDriver

 JDBC-ODBC Bridge Driver - Flat Text Files

 JDBC-ODBC Bridge Driver - MS Access

 JDBC-ODBC Bridge Driver - MS SQL Server

 Summary of JDBC Drivers and Database Servers

 Using Connection Pool with JDBC

 Archived Tutorials


 Full Version in PDF/EPUB