8

I am new to java, i have installed Oracle Database 11g Express Edition, and also sql developer.

I have referenced this link How to create a new database after initally installing oracle database 11g Express Edition?, but this is some what differences,

I want to know, how to create new database and retrieve data and display data using java.

I want to know, like as php and phpmyadmin. And also i confused with oracle documentation.

Please help me.. Thanks in advance.

Community
  • 1
  • 1
  • 3
    have you heard of our lord and savior `google`? – MihaiC Dec 08 '14 at 12:01
  • So what's the question? If it's "I want to know, how to create new database and retrieve data and display data using java" then please consult JDBC API http://docs.oracle.com/javase/tutorial/jdbc/basics/gettingstarted.html It has many examples and everything is clear, just take a little time to understand concepts. I dont know if there is such GUI in oracle as phpmyadmin. – drgPP Dec 08 '14 at 12:01
  • @MihaiC: referenced lot of links, but i just struggling.. if you help me step by step.. it will useful for me –  Dec 08 '14 at 12:03
  • @selva that is impossible to do. it depends on your oracle database version, what installation kit you used and so on. it's too complex of an answer – MihaiC Dec 08 '14 at 12:04
  • @MihaiC: I used oracle 11g, You are all senior of java, so If you have not answer me, what can i do, how to fix my problem? –  Dec 08 '14 at 12:07

2 Answers2

19

Before you create a database, you must create a user who can be connected to that database, to do that :

connect system/password;

the password that you entered during the installation.

create user :

create user user1 identified by 'password';

and also to give this user some privileges for creating tables,views and so on . .

grant dba,resource, connect to user;

after that you must connect to that user by typing this :

connect user1/password;

Now you can create tables, like this :

create table exemple(
id int primary key,
name varchar2(255)
);
marsahllDTitch
  • 309
  • 1
  • 8
  • I gone, all start -> progrmms -> oracle database 11g express edition -> run sql command line -> and type connect username, password... now my page look like this http://imgur.com/8nm6a1m –  Dec 08 '14 at 12:21
  • 1
    it's grant dba,resource,connect to selva; – marsahllDTitch Dec 08 '14 at 12:22
  • ok, after that, when i typed, connect selva/password; it shows like this user SELVA lacks CREATE SESSION something like this. –  Dec 08 '14 at 12:29
  • first of all, i need to what is the use of sql developer and oracle database 11g in java?.. please explain separately.. –  Dec 08 '14 at 12:35
  • If you want to connect to the user, it's like this after seeing the picture above, connect selva/system; – marsahllDTitch Dec 08 '14 at 12:36
  • what picture? may i know? –  Dec 08 '14 at 12:38
  • this picture http://imgur.com/8nm6a1m – marsahllDTitch Dec 08 '14 at 12:41
  • now what i do, please help me. –  Dec 08 '14 at 12:42
  • can you give me an image of the error message . . . – marsahllDTitch Dec 08 '14 at 12:46
  • http://imgur.com/K67dVAo –  Dec 08 '14 at 12:49
  • it's obvious that you are giving the grant dba to system, but in fact you must give the priviliges to the user how is selva, in the line when you typed grant dba,resource,connect to system, replace system by selva,it should be like this grant dba,resource,connect to selva; and the probleme will be solved. – marsahllDTitch Dec 08 '14 at 12:56
  • ok connected, after that, where to write this code, create table exemple{ id int primary key, name varchar2(255) } –  Dec 08 '14 at 13:02
  • you can write it after you was connected to the user. – marsahllDTitch Dec 08 '14 at 13:03
  • is it possible in sql command line,, like this {? –  Dec 08 '14 at 13:04
  • like this : create table exemple(id int primary key,name varchar2(255)); – marsahllDTitch Dec 08 '14 at 13:07
  • now it shows, "table created".. after that what can i do..? @mehdi –  Dec 09 '14 at 09:46
  • now it depends what you wanna do in that table, you have multiple choices, like inserting or updating or deleting . . . – marsahllDTitch Dec 09 '14 at 11:20
  • now, i need to know, how to write a java program to connect database and retrieve the data from database and display front end? –  Dec 09 '14 at 11:33
  • 1
    While creating user type create user user1 identified by password; or create user user1 identified by "password"; Sinlge quotes does not work – Dexter May 08 '17 at 19:47
1

In Java it's quite popular to use some ORM solution like Hibernate, and it's been abstracted away to be independent of implementation (like Hibernate) with JPA.

After you have created database you can also use accompanying tools to generate database schema from your domain classes or vice versa.

Edit:

You can create database with Oracle GUI tools like SQL Developer, and then in database you can e.g. run schema generation script (I took this from TechOnTheNet:

CREATE SCHEMA AUTHORIZATION put_your_user_here
     CREATE TABLE products
        ( product_id number(10) not null,
          product_name varchar2(50) not null,
          category varchar2(50),
          CONSTRAINT products_pk PRIMARY KEY (product_id)
         );

Then e.g. try to connect to your db in Java with JDBC or set up and configure some ORM solution (learning curve may be more difficult) and go from there.

  • 2
    Before he's starting with ORM, i think it's good to understand jdbc first, it's my opinion. – drgPP Dec 08 '14 at 12:04
  • he's asking how to install a database. after that he wants to read/write data to it using java. he should start small, with jdbc after he installs his db. – MihaiC Dec 08 '14 at 12:05
  • @kristjan: my sql developer page look like this http://imgur.com/zLVXfW2.. then where i can add your code? –  Dec 08 '14 at 12:13
  • Yes, you have correctly opened empty worksheet, now you can insert SQL there and press green arrow "Run statement" – Kristjan Veskimäe Dec 08 '14 at 12:20
  • @KristjanVeskimäe: now it shows error like this Error at Command Line : 1 Column : 15 Error report - SQL Error: ORA-02420: missing schema authorization clause 02420. 00000 - "missing schema authorization clause" *Cause: the AUTHORIZATION clause is missing from a create schema statement. *Action: Preceed the schema authorization identifier with the AUTHORIZATION keyword. –  Dec 08 '14 at 12:24
  • @KristjanVeskimäe: are you there..? –  Dec 08 '14 at 12:39
  • I edited answer so the schema generation script is Oracle-specific. – Kristjan Veskimäe Dec 08 '14 at 12:52