January 12th, 2008

into the requested data type. Null values are handled specially; the JDBC API has a wasNull method that will return true if the last column that was retrieved was null: public boolean wasNull() throws SQLException { return lastNull; } The SimpleText driver also supports InputStreams. In our case, the SimpleTextInputStream class is just a simple wrapper around a CommonValue object. Thus, if an application requests the data for a column as an InputStream, the SimpleText driver will get the data as a CommonValue object (as it always does) and create an InputStream that fetches the data from the CommonValue. The getMetaData method returns a ResultSetMetaData object, which is our last class to cover. ResultSetMetaData The ResultSetMetaData class provides methods that describe each one of the columns in a result set. This includes the column count, column attributes, and the column name. ResultSetMetaData will typically be the smallest class in a JDBC driver, and is usually very straightforward to implement. For the SimpleText driver, all of the necessary information is retrieved from the Hashtable of column information that is required for all result sets. Thus, to retrieve the column name: public String getColumnLabel( int column) throws SQLException { // Use the column name return getColumnName(column); } protected SimpleTextColumn getColumn( int col) throws SQLException { SimpleTextColumn column = (SimpleTextColumn) inMemoryColumns.get(new Integer(col)); if (column == null) { throw new SQLException(”Invalid column number: ” + col); } return column;
Find the right website host for you, offering a directory of website hosts, free domain name registration tool, hosting reviews, web hosting ratings and articles for beginners, and tons of other resources, check web hosting ratings for more information.

January 11th, 2008

object, and the application can request it in any other supported format. Let s take a look at the getString method: public String getString( int columnIndex) throws SQLException { // Verify the column and get the absolute column number for the // table. int colNo = verify(columnIndex); String s = null; if (inMemoryRows != null) { s = (getColumn(rowNum, columnIndex)).getString(); } else { CommonValue value = getValue(colNo); if (value != null) { s = value.getString(); } } if (s == null) { lastNull = true; } return s; } The method starts out by verifying that the given column number is valid. If it is not, an exception is thrown. Some other types of initialization are also performed. Remember that all ResultSet objects are provided with a Hashtable of SimpleTextColumn objects describing each column: protected int verify( int column) throws SQLException { clearWarnings(); lastNull = false; SimpleTextColumn col = (SimpleTextColumn) inMemoryColumns.get( new Integer(column)); if (col == null) { throw new SQLException(”Invalid column number: ” + column); } return col.colNo; } Next, if the row data is stored in an in-memory Hashtable (as with the DatabaseMetaData catalog methods), the data is retrieved from the Hashtable. Otherwise, the driver gets the data from the data file. In both instances, the data is retrieved as a CommonValue object, and the getString method is used to format the data
You need web hosting, easy to use web template and great support. What else could I ask for?All of our reseller accounts include free web hosting templates just check web hosting templates for more information.

January 10th, 2008

they were not necessary; if an application wanted to get data in this manner, then the application could provide a routine to cross reference the column name to a column number. Unfortunately (in my opinion), JavaSoft chose to keep these methods in the API and provide the implementation of the cross reference method in an appendix. Because it is part of the API, all drivers must implement the methods. Implementing the methods is not all that difficult, but it is tedious and adds overhead to the driver. The driver simply takes the column name that is given, gets the corresponding column number for the column name, and invokes the same get method using the column number: public String getString( String columnName) throws SQLException { return getString(findColumn(columnName)); } And here s the findColumn routine: public int findColumn( String columnName) throws SQLException { // Make a mapping cache if we don’t already have one if (md == null) { md = getMetaData(); s2c = new Hashtable(); } // Look for the mapping in our cache Integer x = (Integer) s2c.get(columnName); if (x != null) { return (x.intValue()); } // OK, we’ll have to use metadata for (int i = 1; i < md.getColumnCount(); i++) { if (md.getColumnName(i).equalsIgnoreCase(columnName)) { // Success! Add an entry to the cache s2c.put(columnName, new Integer(i)); return (i); } } throw new SQLException("Column name not found: " + columnName, "S0022"); } This method uses a Hashtable to cache the column number and column names. It s Your Way, Right Away An application can request column data in any one of the supported JDBC data types. As we have discussed before, the driver should coerce the data into the proper format. The SimpleText driver accomplishes this by using a CommonValue object for all data values. Therefore, the data can be served in any format, stored as a CommonValue
Have you tried other web hosting companies and found out that their focus and your focus are in clash?Check our filemaker web hosting services.

January 9th, 2008

} } catch (Exception ex) { } throw new SQLException(”Unknown object type”); } Setting InputStreams As we ll see with ResultSet later, using InputStreams is the recommended way to work with long data (blobs). There are two ways to treat InputStreams when using them as input parameters: Read the entire InputStream when the parameter is set and treat it as a large data object, or defer the read until the statement is executed and read it in chunks at a time. The latter approach is the preferred method because the contents of an InputStream may be too large to fit into memory. Here s what the SimpleText driver does with InputStreams: public void setBinaryStream( int parameterIndex, java.io.InputStream x, int length) throws SQLException { // Validate the parameter index verify(parameterIndex); // Read in the entire InputStream all at once. A more optimal // way of handling this would be to defer the read until execute // time, and only read in chunks at a time. byte b[] = new byte[length]; try { x.read(b); } catch (Exception ex) { throw new SQLException(”Unable to read InputStream: ” + ex.getMessage()); } // Set the data as a byte array setBytes(parameterIndex, b); } But wait, this isn t the preferred way! You are correct, it isn t. The SimpleText driver simply reads in the entire InputStream and then sets the parameter as a byte array. I ll leave it up to you to modify the driver to defer the read until execute time. ResultSet The ResultSet class provides methods to access data generated by a table query. This includes a series of get methods which retrieve data in any one of the JDBC SQL type formats, either by column number or by column name. When the issue of providing get methods was first introduced by JavaSoft, some disgruntled programmers argued that
Adult web hosting has rich experience in providing unique solutions for the customer’s needs, just check frontpage web hosting services.

January 8th, 2008

clearWarnings(); // The paramCount was set when the statement was prepared if ((parameterIndex <= 0) || (parameterIndex > paramCount)) { throw new SQLException(”Invalid parameter number: ” + parameterIndex); } // If the parameter has already been set, clear it if (boundParams.get(new Integer(parameterIndex)) != null) { boundParams.remove(new Integer(parameterIndex)); } } Because the CommonValue class does not yet support all of the JDBC data types, not all of the set methods have been implemented in the SimpleText driver. You can see, however, how easy it would be to fully implement these methods once CommonValue supported all of the necessary data coercion. What Is It? Another way to set parameter values is by using the setObject method. This method can easily be built upon the other set methods. Of interest here is the ability to set an Object without giving the JDBC driver the type of driver being set. The SimpleText driver implements a simple method to determine the type of object, given only the object itself: protected int getObjectType( Object x) throws SQLException { // Determine the data type of the Object by attempting to cast // the object. An exception will be thrown if an invalid casting // is attempted. try { if ((String) x != null) { return Types.VARCHAR; } } catch (Exception ex) { } try { if ((Integer) x != null) { return Types.INTEGER; } } catch (Exception ex) { } try { if ((byte[]) x != null) { return Types.VARBINARY;
Sbc yahoo internet provider is a name that we will not do any shame to. We are as good in what we do. Our sbc yahoo web hosting team will work hard to meet and satisfy all your web hosting needs.Try us out!

January 7th, 2008

} // The overloaded executeUpdate on the Statement object (which we // extend) is not valid for PreparedStatement or CallableStatement // objects. public int executeUpdate( String sql) throws SQLException { throw new SQLException(”Method is not valid”); } // The overloaded execute on the Statement object (which we // extend) is not valid for PreparedStatement or CallableStatement // objects. public boolean execute( String sql) throws SQLException { throw new SQLException(”Method is not valid”); } Setting Parameter Values The PreparedStatement class introduces a series of set methods to set the value of a specified parameter. Take the following SQL statement: INSERT INTO FOO VALUES (?, ?, ?) If this statement was used in creating a PreparedStatement object, you would need to set the value of each parameter before executing it. In the SimpleText driver, parameter values are kept in a Hashtable. The Hashtable contains the parameter number as the key, and a CommonValue object as the data object. By using a CommonValue object, the application can set the parameter using any one of the supported data types, and we can coerce the data into the format that we need in order to bind the parameter. Here s the code for the setString method: public void setString( int parameterIndex, String x) throws SQLException { // Validate the parameter index verify(parameterIndex); // Put the parameter into the boundParams Hashtable boundParams.put(new Integer(parameterIndex), x); } The verify method validates that the given parameter index is valid for the current prepared statement, and also clears any previously bound value for that parameter index: protected void verify( int parameterIndex) throws SQLException {
We strive to offer the highest quality service while maintaining a cheap and discount price structure. For your company, ecommerce, or personal web hosting needs, we offer the best solution.Trust us and please check quality web hosting services.

January 6th, 2008

cumbersome, but when you consider the alternative of wrapping try…catch statements around each operation, this seems like a better solution. Note also that warnings can be chained together, just like SQLExceptions (for more information on chaining, see the JDBC Exception Types section earlier in this chapter). Two (Or More) For The Price Of One Some database systems allow SQL statements that return multiple results (columnar data or an update count) to be executed. If you are unfortunate enough to be developing a JDBC driver using one of these database systems, take heart. The JDBC specification does address this issue. The getMoreResults method is intended to move through the results. Figuring out when you have reached the end of the results, however, is a bit convoluted. To do so, you first call getMoreResults. If it returns true, there is another ResultSet present and you can use getResultSet to retrieve it. If getMoreResults returns false, you have either reached the end of the results, or an update count exists; you must call getUpdateCount to determine which situation exists. If getUpdateCount returns -1, you have reached the end of the results; otherwise, it will return the number of rows affected by the statement. The SimpleText driver does not support multiple result sets, so I don t have any example code to present to you. The only DBMS that I am aware of that supports this is Sybase. Because there are already multiple JDBC drivers available for Sybase (one of which I have developed), I doubt you will have to be concerned with getMoreResults. Consider yourself lucky. PreparedStatement The PreparedStatement is used for pre-compiling an SQL statement, typically in conjunction with parameters, and can be efficiently executed multiple times with just a change in a parameter value; the SQL statement does not have to be parsed and compiled each time. Because the PreparedStatement class extends the Statement class, you will have already implemented a majority of the methods. The executeQuery, executeUpdate, and execute methods are very similar to the Statement methods of the same name, but they do not take an SQL statement as a parameter. The SQL statement for the PreparedStatement was provided when the object was created with the prepareStatement method from the Connection object. One danger to note here: Because PreparedStatement is derived from the Statement class, all of the methods in Statement are also in PreparedStatement. The three execute methods from the Statement class that accept SQL statements are not valid for the PreparedStatement class. To prevent an application from invoking these methods, the driver should also implement them in PreparedStatement, as shown here: // The overloaded executeQuery on the Statement object (which we // extend) is not valid for PreparedStatement or CallableStatement // objects. public ResultSet executeQuery( String sql) throws SQLException { throw new SQLException(”Method is not valid”);
Do you want something as professional as you are? Well, we are, but our plans are even better, please check Web Hosting SSH and look why we are the best.

January 5th, 2008

// // sql an SQL INSERT, UPDATE, or DELETE statement, or an SQL // statement that returns nothing. // // Returns either the row count for INSERT, UPDATE, or DELETE; or 0 // for SQL statements that return nothing. //———————————————————————- — public int executeUpdate( String sql) throws SQLException { if (traceOn()) { trace(”@executeUpdate(” + sql + “)”); } int count = -1; // Execute the query. If execute returns false, then an update // count exists. if (execute(sql) == false) { count = getUpdateCount(); } else { // If the statement does not create an update count, the // specification indicates that an SQLException should be raised. throw new SQLException(”Statement did not create an update count”); } return count; } As you can see, executeQuery and executeUpdate are simply helper methods for an application; they are built completely upon other methods contained within the class. The execute method accepts an SQL statement as its only parameter, and will be implemented differently, depending upon the underlying database system. For the SimpleText driver, the SQL statement will be parsed, prepared, and executed. Note that parameter markers are not allowed when executing an SQL statement directly. If the SQL statement created results containing columnar data, execute will return true; if the statement created a count of rows affected, execute will return false. If execute returns true, the application then uses getResultSet to return the current result information; otherwise, getUpdateCount will return the number of rows affected. Warnings As opposed to SQLException, which indicates a critical error, an SQLWarning can be issued to provide additional information to the application. Even though SQLWarning is derived from SQLException, warnings are not thrown. Instead, if a warning is issued, it is placed on a warning stack with the Statement object (the same holds true for the Connection and ResultSet objects). The application must then check for warnings after every operation using the getWarnings method. At first, this may seem a bit
Our unmatched NT experience allows us to provide the most reliable and affordable hosting for our customers, just check NT Web Hosting services.

January 4th, 2008

handled by the ResultSet class. For now, just note that it can handle both in-memory results (in the form of a Hashtable) and results read directly from the data file. Statement The Statement class contains methods to execute SQL statements directly against the database and to obtain the results. A Statement object is created using the createStatement method from the Connection object. Of note in Listing 10.21 are the three methods used to execute SQL statements: executeUpdate, executeQuery, and execute. In actuality, you only need to worry about implementing the execute method; the other methods use it to perform their work. In fact, the code provided in the SimpleText driver should be identical for all JDBC drivers. Listing 10.21 Executing SQL statements. //———————————————————————- — // executeQuery - JDBC API // Execute an SQL statement that returns a single ResultSet. // // sql Typically this is a static SQL SELECT statement. // // Returns the table of data produced by the SQL statement. //———————————————————————- — public ResultSet executeQuery( String sql) throws SQLException { if (traceOn()) { trace(”@executeQuery(” + sql + “)”); } java.sql.ResultSet rs = null; // Execute the query. If execute returns true, then a result set // exists. if (execute(sql)) { rs = getResultSet(); } else { // If the statement does not create a ResultSet, the // specification indicates that an SQLException should // be raised. throw new SQLException(”Statement did not create a ResultSet”); } return rs; } //———————————————————————- — // executeUpdate - JDBC API // Execute an SQL INSERT, UPDATE, or DELETE statement. In addition, // SQL statements that return nothing, such as SQL DDL statements, // can be executed.
Get account with us and you will get completely access to our free web templates database with over 10.000 templates in it to build your website.Don’t wait, go and check free web templates.

January 4th, 2008

// name here. tableEntry = new SimpleTextTable(dir, entries[i]); list.put(new Integer(i), tableEntry); } } return list; } Again, I use a Hashtable for each table (or file in our case) that is found. By now, you will have realized that I really like using Hashtables; they can grow in size dynamically and provide quick access to data. And because a Hashtable stores data as an abstract Object, I can store whatever is necessary. In this case, each Hashtable entry for a table contains a SimpleTextTable object: public class SimpleTextTable extends Object { //———————————————————————- — // Constructor //———————————————————————- — public SimpleTextTable( String dir, String file) { this.dir = dir; this.file = file; // If the filename has the .SDF extension, get rid of it if (file.endsWith(SimpleTextDefine.DATA_FILE_EXT)) { name = file.substring(0, file.length() - SimpleTextDefine.DATA_FILE_EXT.length()); } else { name = file; } } public String dir; public String file; public String name; } Notice that the constructor strips the file extension from the given file name, creating the table name. Now, back to the getTables method for DatabaseMetaData. Once a list of all of the tables has been retrieved, the Hashtable used for storing all of the rows is generated. If you were to add additional filtering, this is the place that it should be done. Finally, a new ResultSet object is created and initialized. One of the constructors for the ResultSet class accepts two Hashtables: one for the column information (SimpleTextColumn objects), and the other for row data (CommonValue objects). We ll see later how these are
The UK has been a member of the European Union since 1973. The attitude of the present government towards further integration is conservative, with the official opposition favoring a return of some powers and competencies to the UK.From our experience, we can recommend Cheap UK Web Hosting services.