Configuration of Eclipse+tomcat+mysql on Mac

Source: Internet
Author: User

Source: http://stephen830.iteye.com/blog/2001939

Install MySQL

MySQL Community Server (GPL) 5.6.15

Installing tomcat7.0

http://tomcat.apache.org/download-70.cgi

The download is in the tar version

Installing jdk1.7

Install Eclipse


When you start eclipse and say you can't find the JDK, you automatically download a 1.6 jdk.

After Eclipse was launched, it found that there were 2 JRE.



Or select the 1.7 jdk that was previously installed.

Configuring environment Variables Jdk_home and Catalina_home

Open a terminal:

Ruby Code
    1. CD ~

Switch to your user directory, create a new file, filename. bash_profile

Input content

Export Java_home= your JDK directory

Export Catalina_home= your Tomcat directory

JDK directory you can copy directly from the configuration information of Eclipse



Start Tomcat

CD $CATALINA _home/bin

./startup.sh

Open Browser input, http://localhost:8080/

If there is a display, it indicates a successful configuration.

Download the Java driver for MySQL and place it in the Tomcat Lib directory.

Create a new Dynamic web App on Eclipse, configure the Jndi database connection pool,

Add a file under Meta-inf context.xml

XML code
  1. <Context>
  2. <!--MySQL DBCP --
  3. <Resource name="Jdbc/mydb" auth="Container" type="Javax.sql.DataSource"
  4. driverclassname= "com.mysql.jdbc.Driver" url="Jdbc:mysql://localhost:3306/mydb "
  5. username= "mydb" password="123456" maxactive= "" "maxidle="
  6. maxwait="10000" />
  7. </Context>

Add the following in Web. XML under Web-inf:

XML code
  1. <resource-ref>
  2. <description>my DB Connection</description>
  3. <res-ref-name>jdbc/mydb</res-ref-name>
  4. <res-type>javax.sql.datasource</res-type>
  5. <res-auth>container</res-auth>
  6. </resource-ref>

Before you run the test, make sure that you have the databases and users in your MySQL that are already in use in your configuration.

To test the database code:

Java code
  1. <%@ page language="java" contenttype="text/html; Charset=utf-8 "
  2. pageencoding="UTF-8"%>
  3. <%@ page import="java.util.*,javax.naming.*,java.sql.*,javax.sql.*"%>
  4. <! DOCTYPE HTML public "-//W3C//DTD HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" > " /c8>
  5. <meta http-equiv="Content-type" content= "text/html; Charset=utf-8 ">
  6. <body>
  7. <%
  8. Context CTX = new InitialContext ();
  9. String strlookup = "Java:comp/env/jdbc/mydb";
  10. DataSource ds = (DataSource) ctx.lookup (strlookup);
  11. Connection con = ds.getconnection ();
  12. if (con! = null) {
  13. Out.print ("Success");
  14. }else{
  15. Out.print ("failure");
  16. }
  17. %>
  18. </body>

    • View Picture Attachments

Configuration of Eclipse+tomcat+mysql on Mac

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.