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

📄 opencloselob.java

📁 Java示例100
💻 JAVA
字号:
/* * This sample shows how to open, close BLOB and CLOB * and test whether they are open or not. * * note: 1. It needs jdk1.2 or later version and classes12.zip *       2. It drops, creates, and populates table  *          basic_lob_table including types of BLOB and CLOB */// 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 OpenCloseLob{  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");    // It's faster when auto commit is off    conn.setAutoCommit (false);    // Create a Statement    Statement stmt = conn.createStatement ();    try    {      stmt.execute ("drop table basic_lob_table");    }    catch (SQLException e)    {      // An exception could be raised here if the      // table did not exist already.    }    // Create a table containing a BLOB and a CLOB    stmt.execute ("create table basic_lob_table (x varchar2 (30), " +                  "b blob, c clob)");    // Populate the table    stmt.execute ("insert into basic_lob_table values ('one', " +                  "'010101010101010101010101010101', 'onetwothreefour')");    // Select the lobs    ResultSet rset = stmt.executeQuery ("select * from basic_lob_table");    while (rset.next ())    {      // Get the lobs      BLOB blob = (BLOB) rset.getObject (2);      CLOB clob = (CLOB) rset.getObject (3);      // Open the lobs      System.out.println ("Open the lobs");      blob.open (BLOB.MODE_READWRITE);      clob.open (CLOB.MODE_READWRITE);      // Check if the lobs are opened      System.out.println ("blob.isOpen()="+blob.isOpen());      System.out.println ("clob.isOpen()="+clob.isOpen());      // Close the lobs      System.out.println ("Close the lobs");      blob.close ();      clob.close ();      // Check if the lobs are opened      System.out.println ("blob.isOpen()="+blob.isOpen());      System.out.println ("clob.isOpen()="+clob.isOpen());        }    // Close the ResultSet    rset.close ();    // Close the Statement     stmt.close ();      // Close the connection    conn.close ();  }}

⌨️ 快捷键说明

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