zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    MySQL数据丢失讨论
    分布式系统之Quorum (NRW)算法
    阿里巴巴-OS事业群-OS手机事业部-系统服务部门招聘Java开发工程师,有意者请进来
    EQueue
    ENode 2.0
    关于MySQL的在线扩容
    我收藏的技术知识图(每张都是大图)
    关于实现一个基于文件持久化的EventStore的核心构思
    Actor的原理
    OAuth 2.0 授权原理
  • 原文地址:https://www.cnblogs.com/zhanglala/p/4960118.html
Copyright © 2011-2022 走看看