
What is the default fetch size for the JDBC ODBC driver and how can i fetch a set of results for JDBC ODBC driver?

Fetching results JDBC ODBC Driver
A. The default fetch size of JDBC drivers is 10. In general default fetch size of JDBC drivers is 10. To fetch small number of rows from database, JDBC driver is designed so that it may handle out of memory issues. When you set fetch size 100 , the number of network trips to database will become 10. Now you can see, the performance of your application is improved. So, If you want to retrieve large amount of data from table then set fetch size.
JDBC ODBC Fetch Example
package roseindia.net;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBCsetFetchSize {
public static void main(String[] args) throws SQLException {
Connection con = null
Statement stmt = null;
ResultSet rs = null;
String conUrl = "jdbc:mysql://localhost:3306/";
String driverName = "com.mysql.jdbc.Driver";
String databaseName = "student";
String usrName = "root";
String usrPass = "root";
try {
// Loading Driver
Class.forName(driverName). newInstance();
} catch (ClassNotFoundException e) {
System.out.println(e.toString());
}
try {
// Getting Connection
con = DriverManager.getConnection(conUrl + databaseName, usrName,
usrPass);
stmt = con.createStatement();
stmt.setFetchSize(100);
String query = "SELECT * FROM student'";
rs= stmt.executeUpdate(query);
if (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (Exception e) {
System.out.println(e.toString());
} finally {
// Closing Connection
con.close();
stmt.close();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.