1. Developing CSQL application with Eclipse IDE for Java Developers Using eclipse, we will develop an example application that will document key structures, and demonstrate several API calls. This chapter will cover Eclipse for CSQL client development. This section has the following steps: 1. Overview 2. Preliminary Setup 3. Configuring Eclipse with JDBC Driver 4. Creating Application and Accessing Database data
1.1. Overview The configuration of Eclipse for client access to a database is by adding JDBC Driver to the IDE. To demonstrate, we shall create an example table in the CSQL database and establish a JDBC connection to the CSQL database from the Eclipse IDE. Next, we shall insert, retrieve, update and delete and display the example data in the GUI SQL client.
1.2. Preliminary Setup 1. Download the Eclipse package from the http://www.eclipse.org/downloads/ 2. Extract the (.tar.gz) file to the <Eclipse>/eclipse directory. <Eclipse> is the directory in which eclipse is installed. 3. In one terminal set up the class path of the Driver by using (. ./setupenv.ksh) script, which is present in CSQL root directory. 4. Go to your appropriate directory where you have extracted the package. 5. Run the below script to start the Eclipse IDE $cd eclipse $./eclipse 6. Run the CSQL server in one terminal, Refer CSQL User Manual to know how to download CSQL and start it. Now you will get the below screen,
www.csqldb.com
1
CSQL Programmers’ Guide
Figure 1. Splash Screen
1.3. Configuring Eclipse We can start configuring by performing the below steps,
• Create a New Project • Set up Driver
Create a New Project Go to File in main toolbar, Select New from the drop down menu, a pop-up titled Project appears. Now follow the below steps:
Click on Project titled, a new dialog box will appear
Select the titled Java Project from the drop down menu
Click Next, a new window will create
Type a project name in the Project Name box. (In Figure 2a. – it is CsqlTest)
Click on Finish, then Yes.
www.csqldb.com
2
CSQL Programmers’ Guide
Figure 2a. Create a New Project After creating a new project (CsqlTest), a number application can be run .
Setting up the JDBC Driver The name of the JDBC Driver is CsqlJdbcDriver.jar, which needs to be set in the project properties to interact with CSQL. It is explained in the below steps.
Right Click on CsqlTest (what we created as our new project) in your left hand pan under Package Explorer menu.
Go to Properties title and click on that, it will show a dialog box.
Click on Java Build Path > Libraries > Add External JARS button (Illustrated in Figure 3.) In a new dialog box, select the CsqlJdbcDriver.jar file, which will be under /csql/install/lib directory.
www.csqldb.com
3
CSQL Programmers’ Guide
Figure 3. Setting up Driver
1.4. Creating Application and Accessing Database data We will create an application named CsqlExample.java under CsqlTest project, which will create a table and perform the insert, update and delete operation to access CSQL database. Follow the below steps to perform the above action; Double click on CsqlTest, which is present on your left hand pan. Right click on Src Go to New Class, and give your application name in Name box.(In Figure 4. – it is CsqlExample) Click on Finish Use the below connection string and flag to connect to CSQL database: Class.forName (“csql.jdbc.JdbcSqlDriver”); Connection con = DriverManager.getConnection (“jdbc.csql”, “root”, “manager”);
www.csqldb.com
4
CSQL Programmers’ Guide
Figure 4. Creating a Application Now write the java code to access the database data in CsqlExample.java application.
www.csqldb.com
5
CSQL Programmers’ Guide
Figure 5. Accessing Database data
Summary Running application in Eclipse is a matter of configuring the class path and defining a run configuration.
www.csqldb.com
6
CSQL Programmers’ Guide