Using Eclipse Data Source Explorer

It is sometimes useful if you can see data in database tables from your IDE and can modify it. This is possible in Eclipse JEE using Data Source Explorer. This view is displayed in a tab at the lower pane, just below editors, in the Java EE perspective. If you do not see the view, or have closed the view, you can reopen it by selecting the Window | Show View | Other menu. Type data source in the filter textbox and you should see the view name under the Data Management group. Open the view:

Figure 4.12: Data Source Explorer

Right-click on the Database Connections node and select New. From the list, select MySQL:

Figure 4.13: Select the MySQL Connection Profile

Click Next. If the drivers list is empty, you haven't configured the driver yet. Click on the icon next to the drop-down list for drivers to open the configuration page:

Figure 4.14: Selecting Database Driver in JDBC New Driver Definition page

Select the appropriate MySQL version and click on the JAR List tab:

Figure 4.15: Adding Driver Files in JDBC New Driver Definition page

Remove any files from the Driver files list. Click on the Add JAR/Zip... button. This opens the File Open dialog. Select the JAR file for the MySQL driver version that you have selected. Since Maven has already downloaded the JAR file for you, you can select it from the local Maven repository. On OS X and Linux, the path is ~/.m2/repository/mysql/mysql-connector-java/<version_num>/mysql_connector_java_version_num/mysql-connector-java-version_num.jar (version_num is a placeholder for the actual version number in the path). On Windows, you can find the Maven repository at C:Users{your-username}.m2 and then, the relative path for the MySQL driver is the same as that in OS X.


If you have trouble finding the JAR in the local Maven repository, you can download the JAR file (for the MySQL JDBC driver) from http://dev.mysql.com/downloads/connector/j/.

Once you specify the correct driver JAR file, you need to set the following properties:

Figure 4.16: Setting JDBC driver properties

Click Next and then Finish. A new database connection will be added in Data Source Explorer. You can now browse the database schema and tables:

Figure 4.17: Browsing tables in Data Source Explorer

Right-click on any table to see the menu options available for different actions:

Figure 4.18: Table menu options in Data Source Explorer

Select the Edit menu to open a page in the editor where you can see the existing records in the table. You can also modify or add new data in the same page. Select the Load option to load data from an external file into the table. Select the Extract option to export data from the table.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.134.17