将sql值存储到java中的字符串变量中

时间:2013-06-19 13:14:13

标签: java sql

我想从街道列中的表中获取值。

我有:

Street = "SELECT strStreet FROM tblLocations WHERE" +
            " strLocations='" + Location + "';";
当我稍后尝试打印出街道时,我刚想通出来的

只是打印出上面的字符串而不是值

这就是我所拥有的并且它一直返回,街道的值为空

    Street = "SELECT strStreet FROM tblLocations WHERE" +
            " strLocations='" + Location + "';";

    try {
        //create, execute and close the stmt
        Statement stmt = c.createStatement();
        ResultSet rs = stmt.executeQuery(Street);
        while(rs.next()){
            street = rs.getString("strAddress1");
        }
        System.out.println(street);
        rs.close();
        stmt.close();
    } catch (SQLException ex) {
        System.out.println("there was an issue updating");
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
    }

1 个答案:

答案 0 :(得分:0)

假设其余部分有效,您只在查询中选择strStreet列,但是您尝试从结果集中提取strAddress1列。