CUBRID Through Eclipse SQL Explorer
Table of Contents
Eclipse SQL Explorer is a thin SQL client that allows you to query and browse any JDBC compliant database, including CUBRID. The difference between Eclipse SQL Explorer and other similar tools seems to be its surprisingly fast perfomance. I have got to use other tools, but this one caught my attention with its speed. So, give it a try and you will see yourself.
This Eclipse SQL Editor is open source and hosted on Sourceforge.net. You can download it from the links below.
Eclipse SQL Editor is available in two types:
|Type||Eclipse SQL Editor||Size|
|Standalone Client||SQL Explorer RCP (inc JRE)||~77.0 MB|
|SQL Explorer RCP (exc JRE)||~44.2 MB|
|Eclipse Plugin||SQL Explorer Plugin||~11.5 MB|
To install the Standalone Client, download Eclipse SQL Explorer RCP from the link above, then extract the zipfile and launch sqlexplorer.exe to start the application.
To install the Eclipse Plugin, download Eclipse SQL Explorer plugin and extract the zip file in your eclipse directory (requires Eclipse 3.2 or better). After restarting eclipse with the -clean option, a new SQL Explorer perspective should be available.
Eclipse Update Site
You can install and update Eclipse SQL Explorer via the eclipse update mechanism. The update site for Eclipse SQL Explorer is http://eclipsesql.sourceforge.net/.
Start Eclipse SQL Explorer
This time we will show how to use Eclipse SQL Explorer in a standalone mode. I downloaded the version without all the JAR libraries because I do not need them all. I will use only CUBRID JDBC Driver in this tutorial. First launch the sqlexplorer.exe executable file. You should see the main window as shown below.
Add JDBC Driver
This step can be performed only once when you launch the program for the first time. Let's just check if CUBRID JDBC (or any other driver you want) is present. Choose File ⇒ Preferences.
Then the Preferences window will popup which will display all kinds of JDBC Drivers available.
This time almost all of them are market with red cross icon because I have downloaded the version without JAR libraries. Quickly skim over and if CUBRID JDBC is not available, click on Add button on the right. You will see the following window.
In the new window enter a name for the new driver (e.g. CUBRID JDBC Driver). For Example URL field add jdbc:cubrid:<hostname>:33000:<dbname>:<username>:<password>:. The variables between <> angle brakets will give you a hint that instead of them later when creating a new connection you need to include the actual values. We will see it later. Now we need to add the JDBC driver. For this, click on the Extra Class Path tab and click on the Add JARs... button to browser for the CUBRID JDBC Driver.
In the new Explorer Window locate the CUBRID JDBC Driver which is often located in c:\CUBRID\jdbc\cubrid_jdbc.jar in Windows OS, or in /home/CUBRID/jdbc/cubrid_jdbc.jar in Debian based Linux OS, or in /opt/cubrid/jdbc/cubrid_jdbc.jar in Redhat Linux.
Then press the List Drivers button to automatically list the Driver Class Name in the text field below.
This is all. The CUBRID JDBC Driver has been added. Now if you want to make this driver the default driver, so that every time you create a new connection this driver is chose by default, then press on the Set Default button on the right. Then press OK.
Create New Connection
To establish a new connection click on the Create New Connection Profile button.
In the new connection window fill out all the required fields. Enter any Name for your connection. The CUBRI JDBC Driver should be automatically selected if you chose it before and pressed the Set Default button in the preferences. Otherwise, select manually.
In the URL field you should first see the previous jdbc:cubrid:<hostname>:33000:<dbname>:<username>:<password>: template you have entered before. So, instead of <hostname> enter your host name or IP (if CUBRID is installed locally, then enter localhost). The port number by default is 33000, but sometimes it is 8001. Instead of <dbname> enter your database name (in this case we will connect to the demodb database which comes be default with CUBRID). Instead of <username> enter your database username (for the demodb database it is dba). Instead of <password> enter your database username password (the demodb database does not require password, so you can leave it blank). As a result you should get the connection URL like this: jdbc:cubrid:localhost:33000:demodb:dba::.
Optionally you can choose to Auto Logon, AutoCommit, etc. Press OK to connect to the database.
Common Connection Errors
Cannot connect to a broker
If you see this error when you try to connect to the database, it means something is wrong with your Connection String/URL. Make sure it is correct.
Failed to connect to database server, 'demodb', on the following host(s): localhost
If you see this error when you try to connect to the database, it means your database has not been started. Type cubrid service start to start the CUBRID Service and cubrid server start demodb to start the demodb database.
Using Eclipse SQL Explorer
Once you connect to the database the main window should look like this.
You can view the list of Tables and Views in the Database Structure panel on the right.
Create Table Script
Right click on any table to see possible actions you can apply to it such as Create Table Script. This will generate an SQL script to create the selected table.
When you click on any table in the Database Structure panel, you can see its details in the Database Details panel.
Exported (Foreign) Keys
Eclipse SQL Explorer comes with built in SQL Editor tool which is capable of highlighting the keywords.
SELECT Query Results
If you execute any query, Eclipse SQL Explorer return the results really fast. This is what I like in it.
Notice that with CUBRID you need to use single quotes for strings in your SQL queries.
Export to HTML
You can also right click on the panel to perform various operations such as Export to HTML. The results are displayed in a very neat HTML page.
Common SQL Errors
Often users encounter difficulties to execute SQL queries in CUBRID. The common mistake the make is use the double quotes to enclose strings. This is wrong in CUBRID. This will show you something like the error shown below.
Remeber to use single quotes for strings in your SQL queries.
Database Structure Filters
One of the nice features in Eclipse SQL Explorer is its ability to filter the tables or views which are displayed in the Database Structure panel. For instance, in every CUBRID database there are System Tables, which you as a DBA or a developer almost never need. So, sometimes you want to just hide them to have wider area for your own tables. To do that click on the Filter button on the top right corner of the Database Structure panel.
Choose which tables you want to hide.
As you can see no more System Tables in the panel.