Join David Gassner for an in-depth discussion in this video Limiting the number of fetched rows, part of Java Database Integration with JDBC.
- View Offline
If you're working with a database where the tables have a lot of data, there will be many…times when you need to retrieve only a certain amount of data from the table.…You can limit the number of rows in a couple of different ways.…One approach is to use a method of the statement interface called setMaxRows.…There are some complications in trying to use this, especially with Java 7, where you're…using to try-with-resources block to instantiate your objects.…I'm working in a project called LimitingRows, and I'm starting off with the ResultSet that…contains all of the data from the Tours table.…
I retrieve the data, and then use this method of the Tours class which I have created in a previous video.…The displayData method receives the ResultSet object as an argument, loops through its data,…and displays its data in the console.…I'll run the code and show that I'm retrieving all of the data from the Tours table.…I'll also switch from MySQL where I started to HSQLDB,…and then I'll run the code again and show that it works there as well.…
Author David Gassner explains how to choose a JDBC driver and connect to one or more databases. He also provides detailed instructions on reading, selecting, and updating data; calling stored procedures; managing data via JavaBean classes or with prepared statements; and working with metadata.
- Importing a MySQL database
- Connecting to databases
- Handling JDBC exceptions
- Looping through result sets
- Limiting the number of fetched rows
- Filtering data with prepared statements
- Calling stored procedures
- Inserting, updating, and deleting rows with prepared statements
- Using a persistent database connection
- Committing and rolling back transactions