Statement statement = connection.createStatement();
//使用executeQuery会返回一个结果集
ResultSet resultSet = statement.executeQuery(sql);
/*+--------+-----+----+
| name | age | id |
+--------+-----+----+
| sea | 12 | 1 |
| 路易斯 | 18 | 2 |
| louis | 12 | 4 |
| khan | 18 | 5 |
+--------+-----+----+
4 rows in set (0.02 sec)*/
//使用while循环取出数据
while(resultSet.next()){//让光标向后移动,如果没有更多行,则返回false
String name = resultSet.getString(1);//获取该行的第一列
int age = resultSet.getInt(2);//获取第二列
int id = resultSet.getInt(3);
System.out.println(name + "\t" + age + "\t" + id);
出现错误:
请求帮助!!感谢