ResultSet:结果集对象,封装查询结果
next():游标向下移动一行
getXxx(参数):获取数据
Xxx:代表数据类型 如:int getInt(),String getString()
参数:
int:代表列的编号,从1开始 如getString(1)
String:代表列名称 如 getDouble(“balance”);
package cn.lhy.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class JdbcDemo04 {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/root", "root", "root");
String sql = "select * from account";
Statement sttm = conn.createStatement();
ResultSet resultSet = sttm.executeQuery(sql);
resultSet.next();
String string = resultSet.getString("name");
System.out.println(string);
conn.close();
sttm.close();
}
}
原创文章,作者:jamestackk,如若转载,请注明出处:https://blog.ytso.com/tech/java/277512.html