person.java

来自「java连接Oracle数据库例子(thin/oci)」· Java 代码 · 共 59 行

JAVA
59
字号
import java.sql.*;import oracle.sql.*;public class Person implements ORAData, ORADataFactory{  static final Person _factory = new Person ();  public NUMBER ssn;  public CHAR name;  public CHAR address;  public static ORADataFactory getFactory()  {    return _factory;  }  public Person () {}  public Person (NUMBER ssn, CHAR name, CHAR address)  {    this.ssn = ssn;    this.name = name;    this.address = address;  }  public Datum toDatum(Connection c)     throws SQLException  {    StructDescriptor sd =       StructDescriptor.createDescriptor("SCOTT.PERSON_T", c);    Object [] attributes = { ssn, name, address };    return new STRUCT(sd, c, attributes);  }  public ORAData create(Datum d, int sqlType) throws SQLException  {    if (d == null) return null;    Object [] attributes = ((STRUCT) d).getOracleAttributes();    return new Person ((NUMBER) attributes[0],                                   (CHAR) attributes[1],                                   (CHAR) attributes[2]);  }  public String toString ()   {    try    {      return "SCOTT.PERSON_T: ssn="+ssn.intValue()+        " name="+name.stringValue()+        " address="+address.stringValue();    }    catch (SQLException e)     {      // ignore the error    }    return "some error happened";  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?