📄 statement.java
字号:
// XXX We should do something with the possible ret_stat
}
else if (tmp instanceof PacketColumnNamesResult)
{
names = ((PacketColumnNamesResult)tmp).getColumnNames();
}
else if (tmp instanceof PacketColumnInfoResult)
{
info = ((PacketColumnInfoResult)tmp).getColumnInfo();
}
else if (tmp instanceof PacketColumnOrderResult)
{
// nop
// XXX do we want to do anything with this
}
else if (tmp instanceof PacketTabNameResult)
{
// nop
// XXX What should be done with this information?
}
else if (tmp instanceof PacketControlResult)
{
// nop
// XXX do we want to do anything with this
}
else if (tmp instanceof PacketMsgResult)
{
exception = warningChain.addOrReturn((PacketMsgResult)tmp);
}
else if (tmp instanceof PacketUnknown)
{
// XXX Need to add to the warning chain
}
else
{
throw new SQLException("Trying to get a result set. Found a "
+ tmp.getClass().getName());
}
}
if (exception != null)
{
throw exception;
}
else if (!tds.isResultRow() && !tds.isEndOfResults())
{
// XXX
throw new SQLException("Confused. Was expecting a result row. "
+ "Got a 0x" + Integer.toHexString(tds.peek() & 0xff));
}
// TDS 7.0 includes everything in one subpacket.
if (info != null)
names.merge(info);
results = Constructors.newResultSet(tds, this, names);
}
catch(com.internetcds.jdbc.tds.TdsException e)
{
e.printStackTrace();
throw new SQLException(e.getMessage());
}
catch( java.io.IOException e)
{
e.printStackTrace();
throw new SQLException(e.getMessage());
}
}
//--------------------------JDBC 2.0-----------------------------
/**
* JDBC 2.0
*
* Gives the driver a hint as to the direction in which
* the rows in a result set
* will be processed. The hint applies only to result sets created
* using this Statement object. The default value is
* ResultSet.FETCH_FORWARD.
* <p>Note that this method sets the default fetch direction for
* result sets generated by this <code>Statement</code> object.
* Each result set has its own methods for getting and setting
* its own fetch direction.
* @param direction the initial direction for processing rows
* @exception SQLException if a database access error occurs
* or the given direction
* is not one of ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, or
* ResultSet.FETCH_UNKNOWN
*/
public void setFetchDirection(int direction) throws SQLException
{
NotImplemented();
}
/**
* JDBC 2.0
*
* Retrieves the direction for fetching rows from
* database tables that is the default for result sets
* generated from this <code>Statement</code> object.
* If this <code>Statement</code> object has not set
* a fetch direction by calling the method <code>setFetchDirection</code>,
* the return value is implementation-specific.
*
* @return the default fetch direction for result sets generated
* from this <code>Statement</code> object
* @exception SQLException if a database access error occurs
*/
public int getFetchDirection() throws SQLException
{
NotImplemented();
return 0;
}
/**
* JDBC 2.0
*
* Gives the JDBC driver a hint as to the number of rows that should
* be fetched from the database when more rows are needed. The number
* of rows specified affects only result sets created using this
* statement. If the value specified is zero, then the hint is ignored.
* The default value is zero.
*
* @param rows the number of rows to fetch
* @exception SQLException if a database access error occurs, or the
* condition 0 <= rows <= this.getMaxRows() is not satisfied.
*/
public void setFetchSize(int rows) throws SQLException
{
NotImplemented();
}
/**
* JDBC 2.0
*
* Retrieves the number of result set rows that is the default
* fetch size for result sets
* generated from this <code>Statement</code> object.
* If this <code>Statement</code> object has not set
* a fetch size by calling the method <code>setFetchSize</code>,
* the return value is implementation-specific.
* @return the default fetch size for result sets generated
* from this <code>Statement</code> object
* @exception SQLException if a database access error occurs
*/
public int getFetchSize() throws SQLException
{
NotImplemented();
return 0;
}
/**
* JDBC 2.0
*
* Retrieves the result set concurrency.
*/
public int getResultSetConcurrency() throws SQLException
{
NotImplemented();
return 0;
}
/**
* JDBC 2.0
*
* Determine the result set type.
*/
public int getResultSetType() throws SQLException
{
NotImplemented();
return 0;
}
/**
* JDBC 2.0
*
* Adds a SQL command to the current batch of commmands for the statement.
* This method is optional.
*
* @param sql typically this is a static SQL INSERT or UPDATE statement
* @exception SQLException if a database access error occurs, or the
* driver does not support batch statements
*/
public void addBatch( String sql ) throws SQLException
{
NotImplemented();
}
/**
* JDBC 2.0
*
* Makes the set of commands in the current batch empty.
* This method is optional.
*
* @exception SQLException if a database access error occurs or the
* driver does not support batch statements
*/
public void clearBatch() throws SQLException
{
NotImplemented();
}
/**
* JDBC 2.0
*
* Submits a batch of commands to the database for execution.
* This method is optional.
*
* @return an array of update counts containing one element for each
* command in the batch. The array is ordered according
* to the order in which commands were inserted into the batch.
* @exception SQLException if a database access error occurs or the
* driver does not support batch statements
*/
public int[] executeBatch() throws SQLException
{
NotImplemented();
return null;
}
/**
* JDBC 2.0
*
* Returns the <code>Connection</code> object
* that produced this <code>Statement</code> object.
* @return the connection that produced this statement
* @exception SQLException if a database access error occurs
*/
public java.sql.Connection getConnection() throws SQLException
{
return connection;
}
//---------------------------------------------------------------------
// JDBC 3.0
//---------------------------------------------------------------------
public boolean getMoreResults(int current) throws SQLException {
throw new UnsupportedOperationException("Statement.getMoreResults(int) unsupported");
}
public ResultSet getGeneratedKeys() throws SQLException {
throw new UnsupportedOperationException("Statement.getGeneratedKeys() unsupported");
}
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Statement.executeUpdate(String,int) unsupported");
}
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Statement.executeUpdate(String,int[]) unsupported");
}
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Statement.executeUpdate(String,String[]) unsupported");
}
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Statement.execute(String,int) unsupported");
}
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Statement.execute(String,int[]) unsupported");
}
public boolean execute(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Statement.execute(String,String[]) unsupported");
}
public int getResultSetHoldability() throws SQLException {
throw new UnsupportedOperationException("Statement.getResultSetHoldability() unsupported");
}
static public void main(String args[])
throws java.lang.ClassNotFoundException,
java.lang.IllegalAccessException,
java.lang.InstantiationException,
SQLException
{
String query = null;
String url = url = ""
+ "jdbc:freetds:"
+ "//"
+ "kap"
+ "/"
+ "pubs";
Class.forName("com.internetcds.jdbc.tds.Driver").newInstance();
java.sql.Connection connection;
connection = DriverManager.getConnection(url,
"testuser",
"password");
java.sql.Statement stmt = connection.createStatement();
query = ""
+ "update titles "
+ " set price=price+1.00 "
+ " where title_id='MC3021' or title_id = 'BU1032' ";
int count = stmt.executeUpdate(query);
System.out.println("Updated " + count + " rows.");
query =
""
+"select price, title_id, title, price*ytd_sales gross from titles"
+" where title like 'The%'";
java.sql.ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{
float price = rs.getFloat("price");
if (rs.wasNull())
{
System.out.println("price: null");
}
else
{
System.out.println("price: " + price);
}
String title_id = rs.getString("title_id");
String title = rs.getString("title");
float gross = rs.getFloat("gross");
System.out.println("id: " + title_id);
System.out.println("name: " + title);
System.out.println("gross: " + gross);
System.out.println("");
}
}
public boolean isClosed() {
return isClosed;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -