String | getString(int columnIndex) 以 Java 编程语言中 String 的形式获取此 ResultSet 对象的当前行中指定列的值。 |
String getString(int columnIndex) throws SQLException
String
的形式获取此 ResultSet
对象的当前行中指定列的值。
columnIndex
- 第一个列是 1,第二个列是 2,…… NULL
,则返回值为 null
SQLException
- 如果 columnIndex 无效;如果发生数据库访问错误或在已关闭的结果集上调用此方法程序片段:
……
String name,addr;
Customer cust;
Connection con = obtainConnection();
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery(
"SELECT cust_name, address FROM Customer "
+ "WHERE ssn=" + "'" + id + "'");
if (result.next()) {
name = result.getString(1);
addr = result.getString(2);
cust = new Customer(id,name,addr);
} else {
throw new BrokerException("用户" + id + "的信息没找到 :(");
}
return cust;
……
联系客服