Making It Real 85 The Connector/J (Web cam hosting) code attempts

Making It Real 85 The Connector/J code attempts to build a long by reading the value from the database as a double and applying a downcast to a long. If the value cannot be converted to a long, the exception SQLException will be thrown. Short Since the MySQL database can store shorts, we need to be able to get them out as well. The methods for doing this are short getShort(int columnIndex); short getShort(String columnName); The short values will be obtained using a downcast from a double. The SQLException exception will be thrown if the value returned cannot be converted to a short. Closing the Objects In our example code, we have created many different objects, including Result- Set, Statement, and Connection objects. When we have finished with each of the pieces, they should be closed so that the JVM as well as the Connector/J driver knows that the memory the objects are occupying can be given back to the system. It is important that we close the objects in the reverse order in which they were opened. This means the ResultSet objects should have their close() method called before we call the Connection object s close(). There will be times when closing the objects in the wrong order can produce a SQLException exception. With this in mind, a closed connection from Connector/J to the MySQL database server can cause a SQLException to be thrown if any of the methods (such as createStatement()) can be called against it. The Connection object includes a method called isClosed(), which returns a value of true if the current Connection object has lost its link to the database server. In these cases, the Connection object needs to be reconnected with the database server before any additional work can occur on the object. Making It Real Well, you may not have found our first example very exciting, so let s expand things a little and make them more useful and powerful, as well as add some graphics. Next we create a GUI that will allow us to see all of the account numbers in our database table, select one, and then display the information associated with the account number on the same GUI. Later in the chapter, we expand

Hint: If you are looking for very good and affordable webspace to host and run your tomcat hosting application check Sandzak.com tomcat web hosting provider

Comments are closed.