java getString


今天讀到一段從oracle中讀代碼的代碼,忘了getString(1)什么意思了,特意查了一下學習了一下。

這是文檔中的解釋:要注意1就是第一列

String getString(int columnIndex)
                 throws SQLException
Retrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.
Parameters:
columnIndex - the first column is 1, the second is 2, ...
Returns:
the column value; if the value is SQL NULL, the value returned is null
Throws:
SQLException - if the columnIndex is not valid; if a database access error occurs or this method is called on a closed result set
以 Java 編程語言中  String 的形式獲取此  ResultSet 對象的當前行中指定列的值 
參數:
columnIndex - 第一個列是 1,第二個列是 2,……
返回:
列值;如果值為 SQL  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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM