Settings MySQL Database and JDBC configuration Instructor: Sergey Goldman Instructions for Installing MySQL Installing MySQL Connector/J Test example Java DB Test example Installing Tomcat Instructions for Installing MySQL Database • • • MySQL 5.5 Community Server Edition - open-source database management system that executes on many platforms, including Windows, Solaris, Linux, and Macintosh Download: http://dev.mysql.com/downloads/mysql/5.5.html#downloads • Complete information about MySQL is available from http://www.mysql.com • Installation requirements for your platform: • http://dev.mysql.com/doc/refman/5.5/en/installing.html – Download from • http://dev.mysql.com/downloads/mysql/ – Select OS. Ex, Windows64. – Run the MSI installer Instructions for Installing MySQL Database (cont.) Accept agreement amd Choose Typical for the Setup Type, then Click install Next, next…finish Select Standard Configuration Select Install as Windows Service (optional). Otherwise start manually as mysql-nt.exe Select Include Bin Directory in Windows PATH Select Modify Security Settings. Type password mysql (BTW, in the Deitel book it is root) Select Create An Anonymous Account Execute MySQL running as service Possible Problem: Windows Firewall Exception http://windows.microsoft.com/en-us/windows/open-port-windowsfirewall#1TC=windows-7 Open mssql using command line Another way All Programs->MySQL MySQL Command Line Client Switch to the default mysql database (do not confuse with mysql password!) Important: Create deitel user: Create a deitel user with password is deitel create user 'deitel'@'localhost' identified by 'deitel'; Give deitel user all privileges grant select, insert, update, delete, create, drop, references, execute on *.* to 'deitel'@'localhost'; Logging as deitel user (command prompt) mysql -h localhost -u deitel –p password: deitel Logging as deitel user (another command) mysql –user=deitel –p password: deitel Logging as deitel user (another command) mysql –user=deitel –password=deitel Create books Database • Copy from chapter 28 examples ch28\SQLscripts\mysql books.sql to C:\Program Files\MySQL\MySQL Server 5.5\data Create books Database (cont) • Execute (no ;) source C:\Program Files\MySQL\MySQL Server 5.5\data\books.sql Check books database entries Update path for javac (if not yet done can be a different version) Test Failure (re-compile first) Installing MySQL Connector/J • To use MySQL with JDBC, you also need to install • MySQL Connector/J—a JDBC driver that allows programs to use JDBC to interact with MySQL • MySQL Connector/J can be downloaded from http://dev.mysql.com/downloads/connector/j/5.1.html Get Platform independent mysql-connector-java-5.1.34.zip (latest at that time) OR mysql-connector-java-5.1.14.tar.gz from Deitel’s CD • The documentation for Connector/J is located at http://dev.mysql.com/doc/connector/j/en/connector-j.html • Unzip and get mysql-connector-java-5.1.34-bin.jar Configure Connector/J • • • Unzip the tar.gz (use for example, Winzip) or simply use from CD, or provided by instructor All you need is mysql-connector-java-5.1.34-bin.jar Put it somewhere, for example (change: c:\MySql\sglj) Configure Connector/J cont. Set System CLASSPATH to use this jar .;C:\Program Files\Java\jdk1.7.0_75;c:\MySql\mysqlj\mysql-connector-java5.1.18-bin.jar Re-test (new shell) Apache Tomcat Server • Multiple ways: – Stand alone (download version 7.x from from http://tomcat.apache.org/download-70.cgi) Use Windows service (32/64 installer) or without (32/64 zip) If using zip, install under C:\tomcat Setting Up Environmental Variables for (No windows service) • Define environment variables – CATALINA_HOME • C:\tomcat – CATALINA_BASE • C:\tomcat – JAVA_HOME • C:\Program Files\Java\jdk1.7.0_02 – Add to CLASSPATH • C:\tomcat\lib\servlet-api.jar • C:\tomcat\lib\jsp-api.jar – On some platforms you may need to restart your computer for the new environment variables to take effect Create desktop shortcuts (if not running as service) May need to restart after deploying a new content SETTINGS CATALINA_BASE=C:\tomcat CATALINA_HOME=C:\tomcat CLASSPATH=.;C:\Program Files\Java\jdk1.7.0_02;c:\mysqlj\mysql-connector-java-5.1 .18-bin.jar;C:\Program Files\Java\jdk1.7.0_02\db\lib\derby.jar;C:\tomcat\lib\ser vlet-api.jar;C:\tomcat\lib\jsp-api.jar JAVA_HOME=C:\Program Files\Java\jdk1.7.0_02 Path=.;C:\Program Files\Java\jdk1.7.0_02\bin;C:\Program Files\RSA SecurID Token Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\ Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\ 9.0\DLLShared\;C:\Program Files\ImageConverter Plus;C:\Program Files\ImageConver ter Plus\Microsoft.VC90.CRT;C:\Program Files\ImageConverter Plus\Microsoft.VC90. MFC;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\MySQL\MySQL Server 5.5 \bin Java DB* • As of JDK 7, the open-source, pure Java database Java DB (the Sun branded version of Apache Derby) comes with the JDK • Before you can execute the application in the next section, you must set up the AddressBook- database in Java DB • We use the embedded version of Java DB – There is also a network version that executes similarly to the MySQL DBMS – http://developers.sun.com/javadb/reference/docs/ – read “Getting Started with Java DB” for installation and configuration instructions. Java DB (Windows settings)* • Open the batch file setEmbeddedCP.bat (located in C:\Program Files\Java\jdk1.7.0_02\db\bin), locate the line @rem set DERBY_INSTALL= • Change it to @set DERBY_INSTALL=C:\Program Files\Java\jdk1.7.0_02\db\bin • Open a Command Prompt and change directories to C:\Program Files\Java\jdk1.7.0_02\db\bin • Type setEmbeddedCP.bat and press Enter to set the environment variables required by Java DB • An embedded JavaDb must reside in the same location as the application that manipulates the database • Change to the directory that contains the code, for example: C:\Projects\Forte\_WebPage_cst356_javaWeb\resources\examples\ch 28\fig28_30_32-WithoutDBPredefined • This directory contains a SQL script address.sql that builds the AddressBook database Java DB settings* Execute the command "C:\Program Files\Java\jdk1.7.0_02\db\bin\ij" to start the command-line tool for interacting with Java DB Create database table Adresses* – first delete AddressBook directory – Connect to AddressBook database (will create AddressBook db if not exists) connect 'jdbc:derby:AddressBook;create=true;user=deitel;password=deitel'; – Create database table run 'address.sql'; Test. Compile (javac *.java) and run