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())
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)
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())
1. Query all the data in the table:
SELECT * FROM table
;2、使用JDBC提供的
java.sql.ResultSetMetaData
The 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)