Java Reference
In-Depth Information
setDate( int , Date ) —Inserts a Date object (from the java.sql package) at the
indicated position.
n
setDouble( int , double ) —Inserts a double value at the indicated position.
n
setFloat( int , float ) —Inserts a float value at the indicated position.
n
setInt( int , int ) —Inserts an int value at the indicated position.
n
setLong( int , long ) —Inserts a long value at the indicated position.
n
setShort( int , short ) —Inserts a short value at the indicated position.
n
setString( int , String ) —Inserts a String value at the indicated position.
n
There's also a setNull( int , int ) method that stores SQL's version of a null (empty)
value at the position indicated by the first argument.
The second argument to setNull() should be a class variable from the Types class in
java.sql to indicate what kind of SQL value belongs in that position.
There are class variables for each of the SQL data types. This list, which is not complete,
includes some of the most commonly used variables: BIGINT , BIT , CHAR , DATE , DECIMAL ,
DOUBLE , FLOAT , INTEGER , SMALLINT , TINYINT , and VARCHAR .
The following code puts a null CHAR value at the fifth position in a prepared statement
called ps :
18
ps.setNull(5, Types.CHAR);
The next project demonstrates the use of a prepared statement to add stock quote data to
a database. Quotes are collected from the Yahoo! website.
As a service to people who follow the stock market, Yahoo! offers a Download
Spreadsheet link on its main stock quote page for each ticker symbol.
To see this link, look up a stock quote on Yahoo! or go directly to a page such as
this one:
http://quote.yahoo.com/q?s=sunw&d=v1
Below the price chart, you can find a Download Data link. Here's what the link looks
like for Sun Microsystems:
http://download.finance.yahoo.com/d/quotes.csv?s=SUNW&f=sl1d1t1c1ohgv&e=.csv
Search WWH ::




Custom Search