java类库详细讲解

源代码在线查看: getobjectoracle.html

软件大小: 5593 K
上传用户: add505
关键词: java
下载地址: 免注册下载 普通下载 VIP

相关代码

				
				
				
				Getting an OBJECT Value from an Oracle Table
				(Java Developers Almanac Example)
				
				
				
				
				
				
								    BODY CODE  {font-family: Courier, Monospace;				           font-size: 11pt}				    TABLE, BODY				          {font-family: Verdana, Arial, Helvetica, sans-serif;				           font-size: 10pt}				    PRE   {font-family: Courier, Monospace;				           font-size: 10pt}				    H3    {font-family: Verdana, Arial, Helvetica, sans-serif;				           font-size: 11pt}				    A.eglink {text-decoration: none}				    A:hover.eglink {text-decoration: underline}				    -->
				
				
				
				
				
				The Java Developers Almanac 1.4
				
				        Order this book from Amazon.
				    
				
				
				
				
				
				
				
				
				
				
				
				Home
				    >
				    List of Packages
				    >
				    java.sql
				         [73 examples]
				        
				        >
				        Oracle OBJECTs
				             [5 examples]
				            
				
				  
				    e299.  
				    Getting an OBJECT Value from an Oracle Table
				
				This example retrieves values contained in an Oracle OBJECT type.  The
				example uses the table and types created in
				e296 Creating an OBJECT Type in an Oracle Database.
				
				
				
				    try {
				        // Create a statement
				        Statement stmt = connection.createStatement();
				    
				        // Select rows from object1_table
				        ResultSet resultSet = stmt.executeQuery("SELECT * FROM object1_table");
				    
				        // Get the OBJECT values from each row
				        while (resultSet.next()) {
				            // Get the integer from the first column col_integer of the row
				            int i = resultSet.getInt(1);
				    
				            // Get the object1 value from the second column col_object1
				            oracle.sql.STRUCT object1 = (oracle.sql.STRUCT)resultSet.getObject(2);
				    
				            // Get the object1 values from each row
				            Object[] object1Values = object1.getAttributes();
				    
				            // Get the first value of object1, which is a string
				            String str = (String)object1Values[0];
				    
				            // Get the second value of object1, which is of the type object2
				            oracle.sql.STRUCT object2 = (oracle.sql.STRUCT)object1Values[1];
				    
				            // Get the values of object2
				            Object object2Values[] = object2.getAttributes();
				            str = (String)object2Values[0];
				            BigDecimal num =  (BigDecimal)object2Values[1];
				        }
				    } catch (SQLException e) {
				    }
				
				
				
				
				             Related Examples
				        
				
				
				
				
				e296. 
				    Creating an OBJECT Type in an Oracle Database
				
				
				
				e297. 
				    Inserting an OBJECT Value into an Oracle Table
				
				
				
				e298. 
				    Inserting an OBJECT Value into an Oracle Table Using a Prepared Statement
				
				
				
				e300. 
				    Deleting an OBJECT Type from an Oracle Table
				
				
				
				
				
				
				
				
				        See also: 
				
				    Batching
				  
				
				
				    Connections
				  
				
				
				    Database Meta Data
				  
				
				
				    Deleting Data
				  
				
				
				    Drivers
				  
				
				
				    Importing and Exporting
				  
				
				
				    Inserting and Updating Data
				  
				
				
				    Oracle VARRAYs
				  
				
				
				    Procedures and Functions
				  
				
				
				    Retrieving Data
				  
				
				
				    Scrollable Result Sets
				  
				
				
				    Tables
				  
				
				
				    Updatable Result Sets
				  
				
				
				
				
				
				
				
				
				
				© 2002 Addison-Wesley.
				
				
				
							

相关资源