diff --git a/cookbook/oracleai_demo.ipynb b/cookbook/oracleai_demo.ipynb index 8d67e122833..b3254c1962a 100644 --- a/cookbook/oracleai_demo.ipynb +++ b/cookbook/oracleai_demo.ipynb @@ -86,8 +86,7 @@ "\n", "import oracledb\n", "\n", - "# please update with your username, password, hostname and service_name\n", - "# please make sure this user has sufficient privileges to perform all below\n", + "# Update with your username, password, hostname, and service_name\n", "username = \"\"\n", "password = \"\"\n", "dsn = \"\"\n", @@ -97,40 +96,45 @@ " print(\"Connection successful!\")\n", "\n", " cursor = conn.cursor()\n", - " cursor.execute(\n", - " \"\"\"\n", - " begin\n", - " -- drop user\n", - " begin\n", - " execute immediate 'drop user testuser cascade';\n", - " exception\n", - " when others then\n", - " dbms_output.put_line('Error setting up user.');\n", - " end;\n", - " execute immediate 'create user testuser identified by testuser';\n", - " execute immediate 'grant connect, unlimited tablespace, create credential, create procedure, create any index to testuser';\n", - " execute immediate 'create or replace directory DEMO_PY_DIR as ''/scratch/hroy/view_storage/hroy_devstorage/demo/orachain''';\n", - " execute immediate 'grant read, write on directory DEMO_PY_DIR to public';\n", - " execute immediate 'grant create mining model to testuser';\n", - "\n", - " -- network access\n", - " begin\n", - " DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(\n", - " host => '*',\n", - " ace => xs$ace_type(privilege_list => xs$name_list('connect'),\n", - " principal_name => 'testuser',\n", - " principal_type => xs_acl.ptype_db));\n", - " end;\n", - " end;\n", - " \"\"\"\n", - " )\n", - " print(\"User setup done!\")\n", - " cursor.close()\n", + " try:\n", + " cursor.execute(\n", + " \"\"\"\n", + " begin\n", + " -- Drop user\n", + " begin\n", + " execute immediate 'drop user testuser cascade';\n", + " exception\n", + " when others then\n", + " dbms_output.put_line('Error dropping user: ' || SQLERRM);\n", + " end;\n", + " \n", + " -- Create user and grant privileges\n", + " execute immediate 'create user testuser identified by testuser';\n", + " execute immediate 'grant connect, unlimited tablespace, create credential, create procedure, create any index to testuser';\n", + " execute immediate 'create or replace directory DEMO_PY_DIR as ''/scratch/hroy/view_storage/hroy_devstorage/demo/orachain''';\n", + " execute immediate 'grant read, write on directory DEMO_PY_DIR to public';\n", + " execute immediate 'grant create mining model to testuser';\n", + " \n", + " -- Network access\n", + " begin\n", + " DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(\n", + " host => '*',\n", + " ace => xs$ace_type(privilege_list => xs$name_list('connect'),\n", + " principal_name => 'testuser',\n", + " principal_type => xs_acl.ptype_db)\n", + " );\n", + " end;\n", + " end;\n", + " \"\"\"\n", + " )\n", + " print(\"User setup done!\")\n", + " except Exception as e:\n", + " print(f\"User setup failed with error: {e}\")\n", + " finally:\n", + " cursor.close()\n", " conn.close()\n", "except Exception as e:\n", - " print(\"User setup failed!\")\n", - " cursor.close()\n", - " conn.close()\n", + " print(f\"Connection failed with error: {e}\")\n", " sys.exit(1)" ] },