How to insert OBJECT TYPE Value in Oracle Table?

Below Java code shows, how to insert OBJECT TYPE value in Oracle Table –

 * Created on 05-2011 Copyright(c) All Rights Reserved.
package com.kodehelp.javasql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

 * Created by
 * Date: 5/3/11
public class InsertObjectValue {
    public static void main(String args[]) throws SQLException, ClassNotFoundException {
        final String driver = "oracle.jdbc.driver.OracleDriver";
        final String url = "jdbc:oracle:thin:@HOST:PORT:SID";
        final String USERNAME = "USERNAME";
        final String PASSWORD = "PASSWORD";
        Class.forName(driver); // load Oracle driver
        Connection conn = DriverManager.getConnection(url, USERNAME, PASSWORD);

        Statement stmt = conn.createStatement();
        stmt.execute("CREATE TYPE obj2 AS OBJECT(col_string2 VARCHAR(30), col_integer2 NUMBER)");
        stmt.execute("CREATE TYPE obj1 AS OBJECT(col_string1 VARCHAR(30), col_integer2 obj2)");
        stmt.execute("CREATE TABLE obj1_table(col_integer NUMBER, col_obj1 obj1)");
        stmt.execute("INSERT INTO obj1_table VALUES(1, obj1('str1', obj2('obj2str1', 123)))");



Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.