Java ResultSet.getDouble(int columnIndex)
Syntax
ResultSet.getDouble(int columnIndex) has the following syntax.
double getDouble(int columnIndex) throws SQLException
Example
In the following code shows how to use ResultSet.getDouble(int columnIndex) method.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//from w ww . j av a2s .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(3) * 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();
}
}