Why thin driver is preferred for JDBC? Explain network protocol driver in JDBC. What are the steps involved in creating a JDBC connection? How to get the database details in a Java program? Explain JDBC statement. What are the steps to connect to the database in JDBC? What are the types of JDBC statements? Which JDBC interface is responsible for managing transactions?
How many layers are there in JDBC architecture? What are the design patterns involved in JDBC architecture? Is the connection pool object thread safe? How do you execute stored procedures and functions using JDBC?
What is row prefetching in JDBC? What is the return type of Class. How do you create your own transactions in JDBC? List few good practices in JDBC.
What are the isolation levels defined by JDBC? How can we store images in the database using JDBC? Explain JDBC batch processing and its benefits. Notify me of new comments via email.
Notify me of new posts via email. Skip to content. Share this: Twitter Facebook. Like this: Like Loading Previous What is difference between java. Time and java. TimeStamp in Java. Next What is volatile Variable. Leave a Reply Cancel reply Enter your comment here Fill in your details below or click an icon to log in:.
Can you sync the ResultSet back to the DB? This question just got me curious to how to decide what to choose when, other than tossing a coin :. I disagree with JR's answer. The RowSet is often a good choice, but as always, the best answer depends on your situation and your needs.
Using a RowSet for everything won't yield dysfunctional code, but it can offer slower performance than a ResultSet the common JdbcRowSet implementation is a wrapper for a ResultSet. If you need to use your result object in modular code that requires a JavaBean, then RowSets meet the minimum requirements for Java Beans. As a result, neither Resultset nor RowSets are thread safe. If you are writing code that consumes database queries and translates them into Java data model objects for use in the rest of your application, then it is likely that RowSets are less performant than Resultsets.
In a lot of code that I've been writing, when I receive a JDBC database query, I've been simply using the Resultset to process the retrievd rows immediately into a List of data model objects.
The Resultset doesn't even survive the method call that performs the translation. In my opinion, this is good In this mode, I don't even need any of the newer features of Resultset, let alone RowSet. I simply iterate forward once through the set and generate a List of result rows. There are situations in which RowSets are highly desirable. Since RowSets are serializable and ostensibly "lightweight", the disconnected CachedRowSet for example represents a reasonably efficient mechanism for transmitting database query results between locations, particularly if you want the data to be updateable in situ.
Of course, you could also serialize and transmit a List of objects. RowSet is almost always the right choice, it is more full featured and has all the benefits you listed as well as having specialized implementations for special purposes, like the disconnected CachedRowSet which is what I always use when the data will fit into memory, so I can release the connection back to the pool as quickly as possible to be reused.
At least with a RowSet you can disconnect it and the client doesn't have to care about the implementation. If you are just transferring the results of a query, JDBC specific classes should be part of your public contract. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more. ResultSet vs RowSet: Which one to choose and when?
0コメント