2014-12-02 20 views
0
// Load the database details into the variables. 
String url  = "jdbc:oracle:thin:@localhost:1521:orcl"; 
String user  = "scott"; 
String password = "tiger"; 

// Create the properties object that holds all database details 
Properties props = new Properties(); 
props.put("user", user); 
props.put("password", password); 
props.put("SetBigStringTryClob", "true"); 

try { 
      DriverManager.registerDriver(new OracleDriver()); 
      Connection conn = DriverManager.getConnection(url  , props); 


      // Create a PreparedStatement object 
      PreparedStatement pstmt = null; 

      // Create a ResultSet to hold the records retrieved. 
      ResultSet rset = null; 

      // Create SQL query statement to retrieve records having CLOB data from 
      // the database. 
      String sqlCall = query; 
      pstmt= conn.prepareStatement(sqlCall); 

      // Execute the PrepareStatement 
      rset = pstmt.executeQuery(); 

      //String clobVal = null; 

      // Get the CLOB value larger than 32765 bytes from the resultset 
      while (rset.next()) { 

       String clobVal = rset.getString(1); 
       System.out.println(clobVal); 
      } 

     } catch (SQLException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

我想使用JDBC将Clob数据转换为字符串。我有上面的代码,但它从数据库中返回null,我不明白为什么。 我在oracle中创建了一个函数,它转换的很好,但处理速度很慢。如何从Clob创建一个长字符串?

如何使用JDBC从Clob创建长字符串?我用的Oracle10g

+0

如果'getString()'返回NULL,则表示您的列为NULL,或者您的驱动程序过期。 CLOB列上的'getString()'适用于任何最新的驱动程序。 – 2014-12-02 08:07:50

回答