Professional Documents
Culture Documents
JDBC Interview Questions: Conclusion: Use The Java - Sql.blob Class For Extraction Whenever You Can
JDBC Interview Questions: Conclusion: Use The Java - Sql.blob Class For Extraction Whenever You Can
14) How can I retrieve only the first n rows, second n rows
of a database using a particular WHERE clause ? For
example, if a SELECT typically returns a 1000 rows, how do
first retrieve the 100 rows, then go back and retrieve the
next 100 rows and so on ?
Use the Statement.setFetchSize method to indicate the size of each database fetch. Note
that this method is only available in the Java 2 platform. For Jdk 1.1.X and Jdk 1.0.X, no
standardized way of setting the fetch size exists. Please consult the Db driver manual.
{escape 'escape-character'}
For example, the query
SELECT NAME FROM IDENTIFIERS WHERE ID LIKE '\_%' {escape '\'}
19) How do I insert an image file (or other raw data) into
a database?
All raw data types (including binary documents or images) should be read and uploaded to
the database as an array of bytes, byte[]. Originating from a binary file,
1. Read all data from the file using a FileInputStream.
2. Create a byte array from the read data.
3. Use method setBytes(int index, byte[] data); of java.sql.PreparedStatement to
upload the data.
// Perform insert
int rowsAffected = stmnt.executeUpdate();
}
Connection.setAutoCommit(false);
//..your insert/update/delete goes here
Connection.Commit();
a new transaction is implicitly started.