java - JDBC如何查询某个表中的全部数据
PHPz
PHPz 2017-04-18 09:16:25
0
5
559

有一个数据表,但是不知道行数和列数,用java如何把这个表中的全部数据提取出来。用双重for循环遍历吗。

PHPz
PHPz

学习是最好的投资!

reply all(5)
左手右手慢动作

Isn’t it enough to directly use the sql statement select * from tableName... Use the next() method to iterate...

小葫芦

The method is mentioned above. The next() method is to get one row of data at a time. If not, it returns false, so you can get all the data with while(rs.next())

Peter_Zhu
select * from table;while(res.next())来迭代;
巴扎黑

1. Query all the data in the table: SELECT * FROM table
2、使用JDBC提供的java.sql.ResultSetMetaDataThe class can obtain the number of columns contained in the query result and the name of each column (ColumnLabel) in the query result set;
As mentioned above, use next() to traverse the result set .

左手右手慢动作

SELECT * The data queried from the database is divided into rows.
while(rs.next()) can be seen as determining whether there is a next line.
java.sql.ResultSet provides a method to get columns, rs.getString(1). (Columns are numbered from left to right and start at column 1)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template