Java ResultSet. GetString () method: get the data of string type
•
Java
Grammar 1
getString(int columnIndex)
Example
Connection conn = …… //省略部分代码
String sql = "SELECT username,pwd FROM myTable"; //定义查询sql语句
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getString(1)); //获取数据表中第一列数据值
System.out.println(rs.getString(2)); //获取数据表中第二列数据值
}
Grammar 2
getString(String columnLabel))
Example
Connection conn = …… //省略部分代码
String sql = "SELECT username,pwd FROM myTable";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getString("username")); //获取username列的列值
System.out.println(rs.getString("pwd")); //获取pwd列的列值
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
