temporarylob.java

来自「Java示例100」· Java 代码 · 共 75 行

JAVA
75
字号
/* * This sample shows how to create and free * temporary BLOB and CLOB. * * It needs jdk1.2 or later version and classes12.zip */// You need to import the java.sql package to use JDBCimport java.sql.*;// You need to import the oracle.sql package to use// oracle.sql.BLOBimport oracle.sql.*;class TemporaryLob{  public static void main (String args [])       throws SQLException  {    // Load the Oracle JDBC driver    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());    String url = "jdbc:oracle:oci8:@";    try {      String url1 = System.getProperty("JDBC_URL");      if (url1 != null)        url = url1;    } catch (Exception e) {      // If there is any security exception, ignore it      // and use the default    }    // Connect to the database    Connection conn =      DriverManager.getConnection (url, "hr", "hr");    // Create a temporary BLOB    BLOB tempBlob = BLOB.createTemporary (conn,                                           false,                                           BLOB.DURATION_SESSION);    // See if the BLOB is temporary     System.out.println ("tempBlob.isTemporary()="+                        tempBlob.isTemporary());    // See if the BLOB is temporary use the BLOB utility API    System.out.println ("BLOB.isTemporary(tempBlob)="+                        BLOB.isTemporary(tempBlob));    // Free the temporary BLOB.     // You can also use "BLOB.freeTemporary(tempBlob);".    tempBlob.freeTemporary ();    // Create a temporary CLOB    CLOB tempClob = CLOB.createTemporary (conn,                                           false,                                           CLOB.DURATION_SESSION);    // See if the CLOB is temporary     System.out.println ("tempClob.isTemporary()="+                        tempClob.isTemporary());    // See if the CLOB is temporary use the CLOB utility API    System.out.println ("CLOB.isTemporary(tempClob)="+                        CLOB.isTemporary(tempClob));    // Free the temporary CLOB.     // You can also use "CLOB.freeTemporary(tempClob);".    tempClob.freeTemporary ();    // Close the connection    conn.close();  }}

⌨️ 快捷键说明

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