Java ResultSet.getDouble(String columnLabel)

Syntax

ResultSet.getDouble(String columnLabel) has the following syntax.

double getDouble(String columnLabel)   throws SQLException

Example

In the following code shows how to use ResultSet.getDouble(String columnLabel) method.


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//  ww  w.j  av  a 2  s.c o m
public class Main {
  public static void main(String[] args) throws Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "yourName", "mypwd");
    Statement stmt = conn.createStatement();
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = stmt.executeQuery("SELECT ssn, name, salary FROM EMPLOYEES");
    printRs(rs);

    rs.beforeFirst();

    while (rs.next()) {
      double newSalary = rs.getDouble("salary") * 1.053;
      rs.updateDouble("salary", newSalary);
      rs.updateRow();
    }
    printRs(rs);
    conn.close();
  }

  public static void printRs(ResultSet rs) throws SQLException {
    rs.beforeFirst();

    while (rs.next()) {
      int ssn = rs.getInt("ssn");
      String name = rs.getString("name");
      double salary = rs.getDouble("salary");

      System.out.print("Row Number=" + rs.getRow());
      System.out.print(", SSN: " + ssn);
      System.out.print(", Name: " + name);
      System.out.println(", Salary: $" + salary);
    }
    System.out.println();
  }
}




















Home »
  Java Tutorial »
    java.sql »




DatabaseMetaData
ParameterMetaData
PreparedStatement
ResultSet
Timestamp