Difference between revisions of "Setup MySQL DB in Eclipse"

From Documentation
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
__TOC__
 
__TOC__
  
== Prerequisite ==
+
= Foreword =
 +
ZK framework's architecture allows you to use any database. Here we just give you some hints on how you can connect to MySQL in Eclipse, and such configuration is independent of ZK framework.
 +
 
 +
To see a simple ZK-based example with a database, please check [http://books.zkoss.org/zkessentials-book/master/jpa_integration/index.html ZK Essentials]
 +
 
 +
= Prerequisite =
  
 
'''1.''' The  [http://www.eclipse.org/datatools/ Data Tools Platform (DTP)] is required for setup DB connection, the '''''Eclipse IDE for Java EE Developers''''' distribution of Eclipse we mentioned in [[ZK Studio Essentials]] has already include DTP, so in most case it is not necessary to do extra Eclipse DTP plug-in installation.
 
'''1.''' The  [http://www.eclipse.org/datatools/ Data Tools Platform (DTP)] is required for setup DB connection, the '''''Eclipse IDE for Java EE Developers''''' distribution of Eclipse we mentioned in [[ZK Studio Essentials]] has already include DTP, so in most case it is not necessary to do extra Eclipse DTP plug-in installation.
  
 
'''2.''' Download MySQL Connector/J:<br/>
 
'''2.''' Download MySQL Connector/J:<br/>
:http://dev.mysql.com/downloads/connector/j/
+
:http://dev.mysql.com/downloads/connector/j/ (choose "Platform independent") and download the zip version
 
extract the zip file to a proper location.
 
extract the zip file to a proper location.
  
== Setup Database Connection in MySQL ==
+
'''Note.''' Different versions of Eclipse may have different settings. Please reference Eclipse official documents if the samples/links listed in this page are not matching what you are using.
# Open Data Source Explorer via '''<nowiki>[Window]/[Show View]/[Data Source Explorer]</nowiki>''':<br/>[[Image:001_open_DataSourceExplorer.png]]<br/><br/>
+
 
 +
= Setup Database Connection in MySQL =
 +
# Open Data Source Explorer via '''<nowiki>[Window]/[Show View]/[Other...]/[Data Management/[Data Source Explorer]</nowiki>''':<br/>[[Image:001_open_DataSourceExplorer.png]]<br/><br/>
 
# Right click the Database Connection folder, select '''<nowiki>[New...]</nowiki>'''.<br/>[[Image:001-1_New_Database_in_DataSourceExplorer.png]]<br/><br/>
 
# Right click the Database Connection folder, select '''<nowiki>[New...]</nowiki>'''.<br/>[[Image:001-1_New_Database_in_DataSourceExplorer.png]]<br/><br/>
 
# Select the Database you suppose to connect ( ''MySQL 5.1'' as the example in this document), you can type custom name and description for mnemonic, click <span style="border-style: outset;font-weight: bold">&nbsp;Next&nbsp;&gt;&nbsp;</span>.<br/>[[Image:002_select_DB_Type.png]]<br/><br/>
 
# Select the Database you suppose to connect ( ''MySQL 5.1'' as the example in this document), you can type custom name and description for mnemonic, click <span style="border-style: outset;font-weight: bold">&nbsp;Next&nbsp;&gt;&nbsp;</span>.<br/>[[Image:002_select_DB_Type.png]]<br/><br/>
 
# On next page, click the '''''New Driver Definition''''' icon next to the '''<nowiki>Drivers:</nowiki>''' listbox.<br/>[[Image:003_new_DriverDef.png]]<br/><br/>
 
# On next page, click the '''''New Driver Definition''''' icon next to the '''<nowiki>Drivers:</nowiki>''' listbox.<br/>[[Image:003_new_DriverDef.png]]<br/><br/>
# On the popup window, select the Database Version in '''Name/Type''' tab.<br/>[[Image:004_chose_MySQL_DBVer.png]]<br/><br/>Swith to '''Jar List'''' tab, click <span style="border-style: outset;font-weight: bold">&nbsp;Clear All&nbsp;</span> to clear the default false jar file location.<br/>[[Image:005_clear_redundant_Jar.png]]<br/><br/> then click <span style="border-style: outset;font-weight: bold">&nbsp;Add JAR/Zp...&nbsp;</span>.<br/>[[Image:006_specify_MySQL_connector_Jar.png]]<br/><br/>Locate the jar file inside the folder that just extracted from downloaded MySQL Connector/J zip file.<br/>[[Image:007_locate_MySQL_connector_Jar_file.png]]<br/><br/>Switch to '"Properties" tab, modify the database connection setting according to your MySQL Database configuration, then click <span style="border-style: outset;font-weight: bold">&nbsp;OK&nbsp;</span></br></br>'''Note:'' The JDBC URL format for MySQL Connector/J is as follows, with items in square brackets ([, ]) being optional:
+
# On the popup window, select the Database Version in ''Name/Type'' tab.<br/>[[Image:004_chose_MySQL_DBVer.png]]<br/><br/>
 +
Swith to ''Jar List'' tab, click <span style="border-style: outset;font-weight: bold">&nbsp;Clear All&nbsp;</span> to clear the default false jar file location.<br/>[[Image:005_clear_redundant_Jar.png]]<br/><br/> then click <span style="border-style: outset;font-weight: bold">&nbsp;Add JAR/Zp...&nbsp;</span>.<br/>[[Image:006_specify_MySQL_connector_Jar.png]]<br/><br/>Locate the jar file inside the folder that just extracted from downloaded MySQL Connector/J zip file.<br/>[[Image:007_locate_MySQL_connector_Jar_file.png]]<br/><br/>Switch to '"Properties" tab, modify the database connection setting according to your MySQL Database configuration, then click <span style="border-style: outset;font-weight: bold">&nbsp;OK&nbsp;</span></br></br>'''Note:'' The JDBC URL format for MySQL Connector/J is as follows, with items in square brackets ([, ]) being optional:
  
 
<pre>jdbc:mysql://[host:port],[host:port].../[database][?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...</pre>
 
<pre>jdbc:mysql://[host:port],[host:port].../[database][?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...</pre>
  
If the host name is not specified, it defaults to 127.0.0.1. If the port is not specified, it defaults to 3306, the default port number for MySQL servers. In above image the database name is '''<tt>test</tt>'''
+
If the hostname is not specified, it defaults to 127.0.0.1. If the port is not specified, it defaults to 3306, the default port number for MySQL servers. In above image the database name is '''<tt>test</tt>'''
  
 
<pre>jdbc:mysql://localhost:3306/test</pre><br/>[[Image:008_specify_MySQL_connection_setting.png]]<br/><br/>
 
<pre>jdbc:mysql://localhost:3306/test</pre><br/>[[Image:008_specify_MySQL_connection_setting.png]]<br/><br/>
 
# To verify if the setup is functional, click <span style="border-style: outset;font-weight: bold">&nbsp;Test Connection&nbsp;</span>.<br/>[[Image:009_test_MySQL_connection.png]]<br/><br/>It should popup a Ping succeeded message, Click  <span style="border-style: outset;font-weight: bold">&nbsp;OK&nbsp;</span> to continue.<br/>[[Image:010_test_MySQL_connection_succeed.png]]<br/><br/>
 
# To verify if the setup is functional, click <span style="border-style: outset;font-weight: bold">&nbsp;Test Connection&nbsp;</span>.<br/>[[Image:009_test_MySQL_connection.png]]<br/><br/>It should popup a Ping succeeded message, Click  <span style="border-style: outset;font-weight: bold">&nbsp;OK&nbsp;</span> to continue.<br/>[[Image:010_test_MySQL_connection_succeed.png]]<br/><br/>
Note: Make sure the MySQL database is up and running. If it is not running, the Test Connection will fail. If you don't know how to find if MySQL is running then please [https://www.google.com/search?q=how+to+check+if+MySQL+is+running google search] it
+
Note: Make sure the MySQL database is up and running. If it is not running, the Test Connection will fail. If you don't know how to find if MySQL is running then please [https://www.google.com/search?q=how+to+check+if+MySQL+is+running google search] it <br/><br/>
 
# Press <span style="border-style: outset;font-weight: bold">&nbsp;Finish&nbsp;</span> to close the setup wizard window, And you should be able to see there's a Database icon in the Database Connections folder.<br/>[[Image:011_MySQL_DB_shown_in_DataSourceExplorer.png]]<br/><br/>
 
# Press <span style="border-style: outset;font-weight: bold">&nbsp;Finish&nbsp;</span> to close the setup wizard window, And you should be able to see there's a Database icon in the Database Connections folder.<br/>[[Image:011_MySQL_DB_shown_in_DataSourceExplorer.png]]<br/><br/>
  
== Note ==
+
= Note =
 
#Firewall of the System that install Database or security setting of the Database may prevent you from connect the DB successfully.
 
#Firewall of the System that install Database or security setting of the Database may prevent you from connect the DB successfully.
 
#If you had specify the right '''MySQL Connector/J''' jar file before, then Step '''4''' &amp; '''5''' can be skipped, you can directly modify the following field to match your MySQL Database configuration<nowiki>:</nowiki><br/>[[Image:012_modify_MySQL_DB_connection_setting.png]]<br/>then proceed the subsequent steps to finish setup.<br/>
 
#If you had specify the right '''MySQL Connector/J''' jar file before, then Step '''4''' &amp; '''5''' can be skipped, you can directly modify the following field to match your MySQL Database configuration<nowiki>:</nowiki><br/>[[Image:012_modify_MySQL_DB_connection_setting.png]]<br/>then proceed the subsequent steps to finish setup.<br/>

Latest revision as of 04:56, 23 August 2018

Foreword

ZK framework's architecture allows you to use any database. Here we just give you some hints on how you can connect to MySQL in Eclipse, and such configuration is independent of ZK framework.

To see a simple ZK-based example with a database, please check ZK Essentials

Prerequisite

1. The Data Tools Platform (DTP) is required for setup DB connection, the Eclipse IDE for Java EE Developers distribution of Eclipse we mentioned in ZK Studio Essentials has already include DTP, so in most case it is not necessary to do extra Eclipse DTP plug-in installation.

2. Download MySQL Connector/J:

http://dev.mysql.com/downloads/connector/j/ (choose "Platform independent") and download the zip version

extract the zip file to a proper location.

Note. Different versions of Eclipse may have different settings. Please reference Eclipse official documents if the samples/links listed in this page are not matching what you are using.

Setup Database Connection in MySQL

  1. Open Data Source Explorer via [Window]/[Show View]/[Other...]/[Data Management/[Data Source Explorer]:
    001 open DataSourceExplorer.png

  2. Right click the Database Connection folder, select [New...].
    001-1 New Database in DataSourceExplorer.png

  3. Select the Database you suppose to connect ( MySQL 5.1 as the example in this document), you can type custom name and description for mnemonic, click  Next > .
    002 select DB Type.png

  4. On next page, click the New Driver Definition icon next to the Drivers: listbox.
    003 new DriverDef.png

  5. On the popup window, select the Database Version in Name/Type tab.
    004 chose MySQL DBVer.png

Swith to Jar List tab, click  Clear All  to clear the default false jar file location.
005 clear redundant Jar.png

then click  Add JAR/Zp... .
006 specify MySQL connector Jar.png

Locate the jar file inside the folder that just extracted from downloaded MySQL Connector/J zip file.
007 locate MySQL connector Jar file.png

Switch to '"Properties" tab, modify the database connection setting according to your MySQL Database configuration, then click  OK 

'Note: The JDBC URL format for MySQL Connector/J is as follows, with items in square brackets ([, ]) being optional:

jdbc:mysql://[host:port],[host:port].../[database][?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...

If the hostname is not specified, it defaults to 127.0.0.1. If the port is not specified, it defaults to 3306, the default port number for MySQL servers. In above image the database name is test

jdbc:mysql://localhost:3306/test


008 specify MySQL connection setting.png

  1. To verify if the setup is functional, click  Test Connection .
    009 test MySQL connection.png

    It should popup a Ping succeeded message, Click  OK  to continue.
    010 test MySQL connection succeed.png

Note: Make sure the MySQL database is up and running. If it is not running, the Test Connection will fail. If you don't know how to find if MySQL is running then please google search it

  1. Press  Finish  to close the setup wizard window, And you should be able to see there's a Database icon in the Database Connections folder.
    011 MySQL DB shown in DataSourceExplorer.png

Note

  1. Firewall of the System that install Database or security setting of the Database may prevent you from connect the DB successfully.
  2. If you had specify the right MySQL Connector/J jar file before, then Step 4 & 5 can be skipped, you can directly modify the following field to match your MySQL Database configuration:
    012 modify MySQL DB connection setting.png
    then proceed the subsequent steps to finish setup.