Opening SQL Scrapbook in Eclipse
Whenever you are working with database applications in eclipse, you might want to open, view and query the database. To do this, you need not open the sql command line. Instead you can connect to the database and view the tables from eclipse. You can open a SQL Scrapbook similar to sql command line where you can query the tables from inside eclipse.
Now, let’s query the table and execute some sql queries from eclipse directly.
To open the SQL Scrapbook, click Window -> show view -> select Data Source Explorer .Select SQL Scrapbook icon from the right corner of Data Source Explorer.
Your SQL Scrapbook opens now.
Select the db Type (For me its oracle 10g) .Once you select this, under Name you get the list of names available for the type. Then select the Database. Since I am using oracle, I get the option as xe.
Once you have selected all the three properly, the Status shows as connected.
The next step is to write the query. I am writing the query as select * from STUDENT. To run this right click inside the window and select Execute Current Text or Alt + S.
Now, come back to Data Source Explorer Tab. Click on SQL Results tab. Click Results. You can see the results of your query.
Let’s try one more example. We will try to insert values into a table.I will write the query as INSERT INTO STUDENT VALUES(‘JOEY’,18,’BANGALORE’);. To run this, select the query, right click inside the window and select Execute Selected Text .
Now, come back to Data Source Explorer Tab. Click on SQL Results tab. Click Results. You can see the status as inserted.
To view the table, click Data Source Explorer Tab. select the schema, then select your table-> right click ->Data ->Edit.
The table is opened now. Select F5 or right click and select Refresh.
You can see the values inserted in the table.