⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdbc.sgml

📁 关系型数据库 Postgresql 6.5.2
💻 SGML
📖 第 1 页 / 共 5 页
字号:
        Parameters:                x - double coordinate                y - double coordinate public void setLocation(int x,                         int y)          Moves the point to the supplied coordinates. refer to          java.awt.Point for description of this        Parameters:                x - integer coordinate                y - integer coordinate        See Also:                Point public void setLocation(Point p)          Moves the point to the supplied java.awt.Point refer to          java.awt.Point for description of this        Parameters:                p - Point to move to        See Also:                PointClass postgresql.geometric.PGpolygon                                java.lang.Object   |   +----postgresql.util.PGobject           |           +----postgresql.geometric.PGpolygon   public class PGpolygon extends PGobject implements Serializable, Cloneable                  This implements the polygon datatype within PostgreSQL.Variables public PGpoint points[]          The points defining the polygon                                Constructors public PGpolygon(PGpoint points[])          Creates a polygon using an array of PGpoints        Parameters:                points - the points defining the polygon public PGpolygon(String s) throws SQLException                         Parameters:                s - definition of the circle in PostgreSQL's syntax.        Throws: SQLException                on conversion failure public PGpolygon()          Required by the driverMethods public void setValue(String s) throws SQLException        Parameters:                s - Definition of the polygon in PostgreSQL's syntax        Throws: SQLException                on conversion failure        Overrides:                setValue in class PGobject public boolean equals(Object obj)             Parameters:                obj - Object to compare with                                        Returns:                true if the two boxes are identical        Overrides:                equals in class PGobject public Object clone()                  This must be overidden to allow the object to be cloned        Overrides:                clone in class PGobject                  public String getValue()        Returns:                the PGpolygon in the syntax expected by postgresql        Overrides:                getValue in class PGobjectLarge ObjectsLarge objects are supported in the standard <acronym>JDBC</acronym> specification. However, that interface is limited, and the api provided by PostgreSQL allows for random access to the objects contents, as if it was a local file.The postgresql.largeobject package profides to Java the libpq C interface's large object <acronym>API</acronym>. It consists of two classes, LargeObjectManager, which deals with creating, opening and deleting large obejects, and LargeObject which deals with an individual object.Class postgresql.largeobject.LargeObjectjava.lang.Object   |   +----postgresql.largeobject.LargeObjectpublic class LargeObject extends ObjectThis class implements the large object interface to postgresql.   It provides the basic methods required to run the interface, plus a pair of methods that provide InputStream and OutputStream classes for this object.   Normally, client code would use the getAsciiStream, getBinaryStream, or getUnicodeStream methods in ResultSet, or setAsciiStream, setBinaryStream, or setUnicodeStream methods in PreparedStatement to access Large Objects.   However, sometimes lower level access to Large Objects are required, that are not supported by the <acronym>JDBC</acronym> specification.   Refer to postgresql.largeobject.LargeObjectManager on how to gain access to a Large Object, or how to create one.   See Also:          LargeObjectManagerVariables public static final int SEEK_SET          Indicates a seek from the begining of a file public static final int SEEK_CUR          Indicates a seek from the current position public static final int SEEK_END          Indicates a seek from the end of a fileMethods public int getOID()        Returns:                the OID of this LargeObject public void close() throws SQLException          This method closes the object. You must not call methods in this object after this is called.    Throws: SQLException                if a database-access error occurs. public byte[] read(int len) throws SQLException          Reads some data from the object, and return as a byte[] array        Parameters:                len - number of bytes to read        Returns:                byte[] array containing data read        Throws: SQLException                if a database-access error occurs. public void read(byte buf[],                  int off,                  int len) throws SQLException          Reads some data from the object into an existing array        Parameters:                buf - destination array                off - offset within array                len - number of bytes to read        Throws: SQLException                if a database-access error occurs. public void write(byte buf[]) throws SQLException          Writes an array to the object        Parameters:                buf - array to write        Throws: SQLException                if a database-access error occurs. public void write(byte buf[],                   int off,                   int len) throws SQLException          Writes some data from an array to the object        Parameters:                buf - destination array                off - offset within array                len - number of bytes to write        Throws: SQLException                if a database-access error occurs. public void seek(int pos,                  int ref) throws SQLException          Sets the current position within the object.          This is similar to the fseek() call in the standard C library.It allows you to have random access to the large object.        Parameters:                pos - position within object                ref - Either SEEK_SET, SEEK_CUR or SEEK_END        Throws: SQLException                if a database-access error occurs. public void seek(int pos) throws SQLException          Sets the current position within the object.          This is similar to the fseek() call in the standard C library.It allows you to have random access to the large object.        Parameters:                pos - position within object from begining        Throws: SQLException                if a database-access error occurs. public int tell() throws SQLException        Returns:                the current position within the object        Throws: SQLException                if a database-access error occurs. public int size() throws SQLException          This method is inefficient, as the only way to find out the size of the object is to seek to the end, record the current position, then return to the original position.          A better method will be found in the future.        Returns:                the size of the large object        Throws: SQLException                if a database-access error occurs. public InputStream getInputStream() throws SQLException          Returns an InputStream from this object.          This InputStream can then be used in any method that requires an InputStream.        Throws: SQLException                if a database-access error occurs. public OutputStream getOutputStream() throws SQLException          Returns an OutputStream to this object          This OutputStream can then be used in any method that requires an OutputStream.        Throws: SQLException                if a database-access error occurs.Class postgresql.largeobject.LargeObjectManager                                java.lang.Object   |   +----postgresql.largeobject.LargeObjectManagerpublic class LargeObjectManager extends ObjectThis class implements the large object interface to postgresql.           It provides methods that allow client code to create, open and delete large objects from the database. When opening an object, an instance of postgresql.largeobject.LargeObject is returned, and its methods then allow access to the object.This class can only be created by postgresql.ConnectionTo get access to this class, use the following segment of code: import postgresql.largeobject.*; Connection  conn; LargeObjectManager lobj; ... code that opens a connection ... lobj = ((postgresql.Connection)myconn).getLargeObjectAPI();Normally, client code would use the getAsciiStream, getBinaryStream, or getUnicodeStream methods in ResultSet, or setAsciiStream, setBinaryStream, or setUnicodeStream methods in PreparedStatement to access Large Objects.   However, sometimes lower level access to Large Objects are required, that are not supported by the <acronym>JDBC</acronym> specification.   Refer to postgresql.largeobject.LargeObject on how to manipulate the contents of a Large Object.   See Also:          LargeObjectVariables public static final int WRITE          This mode indicates we want to write to an object public static final int READ          This mode indicates we want to read an object public static final int READWRITE          This mode is the default. It indicates we want read and write access to a large objectMethods public LargeObject open(int oid) throws SQLException                    This opens an existing large object, based on its OID. This          method assumes that READ and WRITE access is required (the default).        Parameters:                oid - of large object        Returns:                LargeObject instance providing access to the object        Throws: SQLException                on error public LargeObject open(int oid,                         int mode) throws SQLException                    This opens an existing large object, based on its OID          Parameters:                oid - of large object                mode - mode of open        Returns:                LargeObject instance providing access to the object        Throws: SQLException                on error public int create() throws SQLException          This creates a large object, returning its OID.          It defaults to READWRITE for the new object's attributes.        Returns:                oid of new object        Throws: SQLException                on error public int create(int mode) throws SQLException          This creates a large object, returning its OID        Parameters:                mode - a bitmask describing different attributes of the                new object        Returns:                oid of new object        Throws: SQLException                on error public void delete(int oid) throws SQLException                    This deletes a large object.                  Parameters:                oid - describing object to delete        Throws: SQLException                on error public void unlink(int oid) throws SQLException          This deletes a large object.          It is identical to the delete method, and is supplied as the C <acronym>API</acronym> uses unlink.        Parameters:                oid - describing object to delete        Throws: SQLException                on errorObject SerialisationPostgreSQL is not a normal SQL Database. It is far more extensible than most other databases, and does support Object Oriented features that are unique to it. One of the consequences of this, is that you can have one table refer to a row in another table. For example:test=> create table users (username name,fullname text);CREATEtest=> create table server (servername name,adminuser users);CREATEtest=> insert into users values ('peter','Peter Mount');INSERT 2610132 1test=> insert into server values ('maidast',2610132::users);INSERT 2610133 1test=> select * from users;username|fullname      --------+--------------peter   |Peter Mount   (1 row)test=> select * from server;servername|adminuser----------+---------maidast   |  2610132(1 row)Ok, the above example shows that we can use a table name as a field, and the row's oid value is stored in that field.What does this have to do with Java?In Java, you can store an object to a Stream as long as it's class implements the java.io.Serializable interface. This process, known as Object Serialization, can be used to store complex objects into the database.Now, under <acronym>JDBC</acronym>, you would have to use a LargeObject to store them. However, you cannot perform queries on those objects.What the postgresql.util.Serialize class does, is provide a means of storing an object as a table, and to retrieve that object from a table. In most cases, you would not need to access this class direct, but you would use the PreparedStatement.setObject() and ResultSet.getObject() methods. Those methods will check the objects class name against the table's in the database. If a match is found, it assumes that the object is a Serialized object, and retrieves it from that table. As it does so, if the object contains other serialized objects, then it recurses down the tree.Sound's complicated? In fact, it's simpler than what I wrote - it's just difficult to explain.The only time you would access this class, is to use the create() methods. These are not used by the driver, but issue one or more "create table" statements to the database, based on a Java Object or Class that you want to serialize.

⌨️ 快捷键说明

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