展开全部
给你几个方法32313133353236313431303231363533e58685e5aeb931333337383866:
/**
* insert a Row into Orders table using Updateable ResultSet.
*/
public void insertNewRowIntoOrdersTableUsingColumnNames(ResultSet rs)
throws SQLException {
// this method works only if the table is Orders Table in the Demo
// database.
// if the table is different you should change most of this code
// for that purpose.
rs.moveToInsertRow();
rs.updateInt("CUSTOMER_ID_FK", 101);
rs.updateInt("ORDER_ID", 1001);
rs.updateDate("ORDER_DATE", new Date(System.currentTimeMillis()) );
rs.updateString("SHIP_INSTRUCT",
" deliver at Apt. office" + " if no one at home");
rs.updateString("BACKLOG", "N");
rs.updateString("PO_NUM", "BSD100");
rs.updateDate("SHIP_DATE", new Date(System.currentTimeMillis()));
rs.updateFloat("SHIP_WEIGHT", 22.0f);
rs.updateFloat("SHIP_CHARGE", 44.56f);
rs.updateDate("PAID_DATE", new Date(System.currentTimeMillis()));
rs.insertRow();
}
/**
* insert a Row into Orders table using Updateable ResultSet
*/
public void insertNewRowIntoOrdersTableUsingColumnIndexes(ResultSet rs)
throws SQLException {
rs.moveToInsertRow();
rs.updateInt(1, 101);
rs.updateInt(2, 1001);
rs.updateDate(3, new Date(System.currentTimeMillis()));
rs.updateString(4, " deliver at Apt. office if no one at home");
rs.updateString(5, "N");
rs.updateString(5, "BSD100");
rs.updateDate(6, new Date(System.currentTimeMillis()));
rs.updateFloat(7, 22.0f);
rs.updateFloat(8, 44.56f);
rs.updateDate(9, new Date(System.currentTimeMillis()) );
rs.insertRow();
}
/**
* This method deletes nth Row from the result Set
*/
public void deleteNthRow(ResultSet rs,
int rowNum) throws SQLException {
rs.absolute(rowNum);
rs.deleteRow();
}
/**
* this methods updates a value for the nthRow , ith Column .
*/
public void updateNthRowIthColumnValue(ResultSet rs, int nThRow,
int iThColumn,
Object value) throws SQLException {
ResultSetMetaData rMetaData = rs.getMetaData();
int type = rMetaData.getColumnType(iThColumn);
String colName = rMetaData.getColumnName(iThColumn);
rs.absolute(nThRow);
switch (type) {
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
rs.updateString(colName, value.toString());
break;
case Types.BIT:
rs.updateByte(colName,
Byte.valueOf(value.toString()).byteValue());
break;
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
rs.updateInt(colName,
Integer.valueOf(value.toString()).intValue());
break;
case Types.BIGINT:
rs.updateLong(colName,
Long.valueOf(value.toString()).longValue());
break;
case Types.FLOAT:
rs.updateFloat(colName,
Float.valueOf(value.toString()).floatValue());
break;
case Types.DOUBLE:
rs.updateDouble(colName,
Double.valueOf(value.toString()).doubleValue());
break;
case Types.DATE:
rs.updateDate(colName, Date.valueOf(value.toString()));
break;
case Types.TIME:
rs.updateTime(colName, Time.valueOf(value.toString()));
break;
case Types.TIMESTAMP:
rs.updateTimestamp(colName, Timestamp.valueOf(value.toString()));
break;
default:
rs.updateObject(colName, value);
break;
}
rs.updateRow();
}
/**
* cancel updates in a ResultSet
*/
public void cancelUpdatesInResultSet(ResultSet rs)
throws SQLException {
rs.cancelRowUpdates();
}
/**
* print ResultSet in the Forward Direction from current position;
*/
public void printResultSetRowsInForwardDirection(ResultSet rs)
throws SQLException {
ResultSetMetaData rMetaData = rs.getMetaData();
int nColumns = rMetaData.getColumnCount();
// print metadata
for (int i = 1; i < nColumns; i++) {
System.out.print(rMetaData.getColumnName(i) + " : ");
}
System.out.println(rMetaData.getColumnName(nColumns));
// print row
while (rs.next()) {
for (int i = 1; i < nColumns; i++) {
System.out.print(rs.getString(i) + " : ");
}
System.out.println(rs.getString(nColumns));
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
你对这个回答的评价是?
评论
收起