用SQL Data读写数据库自定义类型(三)

2015-01-23 21:53:20 · 作者: · 浏览: 25
able, you must have a readString() call
and a readInt() call in your readSQL() method. JDBC calls these methods according to
the order in which the attributes appear in the SQL definition of the Oracle object type.




The readSQL() method takes the data that the readXXX() methods read and convert, and
assigns them to the appropriate fields or elements of a custom object class instance.*/
public void readSQL(SQLInput stream, String typeName)throws SQLException//SQL data to Java data

{

sqlUdt = typeName;

h = stream.readInt();

m = stream.readInt();

}

public String toString() {

String res = h + ":" + m;

return res;

}

}

}
附上

Reading SQLData Objects from a Result Set



This section summarizes the steps to read data from an Oracle object into your Java application when you choose the SQLData implementation for your custom object class.
These steps assume you have already defined the Oracle object type, created the corresponding custom object class, updated the type map to define the mapping between the Oracle object and the Java class, and defined a statement object stmt.
Query the database to read the Oracle object into a JDBC result set.
Use the getObject() method of your result set to populate an instance of your custom object class with data from one row of the result set. The getObject() method returns the user-defined SQLData object because the type map contains an entry for Employee.
If you have get methods in your custom object class, then use them to read data from your object attributes. For example, if EMPLOYEE has an EmpName (employee name) of type CHAR, and an EmpNum (employee number) of type NUMBER, then provide a getEmpName() method that returns a Java String and a getEmpNum() method that returns an integer (int). Then invoke them in your Java application, as follows:
If you have set methods in your custom object class, then use them to write data from Java variables in your application to attributes of your Java datatype object.
Prepare a statement that updates an Oracle object in a row of a database table, as appropriate, using the data provided in your Java datatype object.
Use the setObject() method of the prepared statement to bind your Java datatype object to the prepared statement.
Execute the statement, which updates the database.