search

Home  >  Q&A  >  body text

java - JDBC如何查询某个表中的全部数据

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

PHPzPHPz2892 days ago570

reply all(5)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:18:25

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

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:18:25

    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())

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:18:25

    select * from table;while(res.next())来迭代;

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:18:25

    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 .

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:18:25

    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)

    reply
    0
  • Cancelreply