Using JDBC with Java Applications and Applets (Web hosting forums) 76
Using JDBC with Java Applications and Applets 76 Statement object executes a query, it returns a ResultSet object. The default configuration for the Statement object is to return a single ResultSet. If the application needs to work with two different results at the same time, multiple Statement objects will need to be instantiated. As you can see from the API documentation in Appendix B Databases and Tables , the Statement object has quite a few methods associated with it. Throughout this chapter, we cover most of those methods and how they relate to the MySQL database. The Statement object to be used in our example code is created from the Connection object using the method createStatement(), as shown here: Statement statement = connection.createStatement(); When calling the createStatement() object, you must enclose it within a try/catch block and capture any SQLException exceptions. The Connection object contains three different variations of the createStatement() method: Statement createStatement() Instantiates a Statement object to be used for sending queries to the database server. Statement createStatement(int resultSetType, int resultSet Concurrency) Instantiates a Statement object to be used for sending queries to the database server using the provided type and concurrency. Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldabilitiy) Instantiates a Statement object to be used for sending queries to the database server using the provided type, concurrency, and holdability. Three parameters are set for ResultSets when a Statement object is created. These are listed below, and we cover them in more detail when we discuss ResultSet objects: ResultSetType The default is TYPE_SCROLL_INSENSITIVE; the possible values are TYPE_FORWARD_ONLY The ResultSet cursor moves forward. TYPE_SCROLL_INSENSITIVE The cursor may scroll in any direction and is not sensitive to changes. TYPE_SCROLL_SENSITIVE The cursor may scroll in any direction and is sensitive to changes. ResultSetConcurrency This parameter determines whether the ResultSet may be updated in place and the updates automatically applied to the database. The default is CONCUR_READ_ONLY; it is the only option supported by Connector/J.
Note: If you are looking for inexpensive but high quality provider to host and run your serlvet application check Astra servlet hosting services