Ubuntu JSP platform uses JDBC to connect to MySQL database

Source: Internet
Author: User
Tags gz file apache tomcat

Ubuntu 7.04 build Ubuntu JSP Platform development environment mysql+tomcat+apache+j2sdk1.6 enter RPM-Q-A in terminal before all installation starts to see if the RPM is installed and RPM Package Required Software if no RPM is installed, enter sudo apt-get install rpm in terminal.

AD:2014WOT Global Software Technology Summit Beijing Station course video release

Do you know what is the Ubuntu JSP platform? This very advanced application technology will be explained by me very much, Ubuntu JSP platform NB where, below I come to tell about the Ubuntu JSP platform unlimited areas. Build the configuration of Ubuntu JSP platform Jdk6.0+tomcat6+apache2+mysql

Ubuntu 7.04 build Ubuntu JSP Platform development environment mysql+tomcat+apache+j2sdk1.6 enter RPM-Q-A in terminal before all installation starts to see if the RPM is installed and RPM Package required software if not installed RPM enter sudo apt-get install rpm in terminal

One. Install MySQL

sudo apt-get install mysql-server start the MySQL service as root:/etc/init.d/mysql start to stop the MySQL service as root:/etc/init.d/mysql Stop start mysql:mysql-u root-p password

Two. Installing J2SDK

1. Download the JDK installation file to the SUN's website download Download j2sdk Latest version: http://java.sun.com/javase/downloads/netbeans.html This download is Jdk-6u1-linux-i586.bin downloaded to the user folder: The Homefolder (/home/jinye) in the Places drop-down box

2. Install the JDK file in terminal./jdk-6u1-linux-i586.bin after a long list of protocol instructions will ask you to agree with the agreement, type Y enter to start the installation after the installation of the folder named Jdk1.6.0_01

3. Establishing a connection to the JDK ln-s jdk1.6.0.0_01 JDK

Three. Install Tomcat

1. Download the Tomcat installation file in website http://tomcat.apache.org tomcat can choose to download the source code or binary files, this time the download is compressed binary files apache-tomcat-6.0.13.tar.gz

2. Unzip the installation Tomcattar ZXF apache-tomcat-6.0.13.tar.gz The unpacked folder will appear under the current directory apache-tomcat-6.0.13

3. Establish a connection for Tomcat Ln-s apache-tomcat-6.0.13 Tomcat

Four. Configure Environment variables

After the last addition of/etc/profile, run it in the system (restart the host)

    1. PATH= $PATH:/home/jinye/jdk/bin:/home/jinye/jdk/jre/bin
    2. java_home=/HOME/JINYE/JDK
    3. Export Java_home
    4. CLASSPATH="./:/home/jinye/jdk/lib:/home/jinye/jdk/jre/lib"
    5. Export CLASSPATH
    6. catalina_home=/home/jinye/tomcat
    7. Export Catalina_home

Five. Download the installation configuration Apache server

1. Installation
sudo apt-get install apache2

Integration of 2.apache2 and TOMCAT6

  1. sudo install LIBAPACHE2-MOD-JK
  2. Check to see if there are any jk.load in the Apache2 boot module
  3. sudo ls/etc/apache2/mods-enabled/
  4. Cgi.load mod-security.conf php5.conf proxy.conf rewrite.load userdir.load
  5. Jk.load mod-security.load php5.load proxy.load userdir.conf
  6. Modifying the Workers.properties file will tomcat_home and Java_home
  7. Address modified to install JDK and Tomcat address above
  8. sudo gedit/etc/libapache2-mod-jk/workers.properties
  9. workers.tomcat_home=/home/jinye/tomcat
  10. workers.java_home=/HOME/JINYE/JDK
  11. Configure/etc/apache2/apache2.conf
  12. Will #sudo gedit/usr/share/doc/libapache2-mod-jk/httpd_example_apache2.conf inside the content
  13. Copy to Apache2.conf last
  14. Sudo/etc/init.d/apache2 restart
  15. sudo/usr/share/tomcat6/bin/./shutdown.sh
  16. sudo/usr/share/tomcat6/bin/./startup.sh
  17. sudo gedit/etc/rc.local
  18. Modify Jdk_home and Java_home addresses
  19. Export jdk_home=/home/jinye/jdk
  20. Export java_home=/home/jinye/jdk
  21. sudo gedit/etc/apache2/httpd.conf
  22. Open the httpd.conf file and add the following person code to the file:
  23. LoadModule jk_module/usr/lib/apache2/modules/mod_jk.so
  24. Jkworkersfile "/etc/libapache2-mod-jk/workers.properties"
  25. Jklogfile "/var/log/apache2/mod_jk.log"
  26. Jkloglevel Info
  27. Jklogstampformat "[%a%b%d%h:%m:%s%Y]"
  28. Jkmount/*. Ubuntu JSP Platform Ajp13_worker
  29. Jkmount/*/servlet/ajp13_worker
  30. Open the Http://localhost/index.Ubuntu JSP platform
  31. See Apache Tomcat home page instructions for installation and integration success
  32. Jkmount/*. Ubuntu JSP Platform Ajp13_worker
  33. Jkmount/*/servlet/ajp13_worker
  34. The two "Ajp13_worker" in the file
  35. /etc/libapache2-mod-jk/workers.properties
  36. The following lines do not appear in the section that is commented out:
  37. worker.list=ajp13_worker
  38. worker.ajp13_worker.port=8009
  39. worker.ajp13_worker.host=localhost
  40. Worker.ajp13_worker.type=ajp13
  41. Worker.ajp13_worker.lbfactor=1
  42. worker.loadbalancer.balanced_workers=ajp13_worker

Be careful to keep the same when modifying/etc/apache2/httpd.conf

Six. Use JDBC in the Ubuntu JSP platform to connect to the MySQL database

1. Download the JDBC Driver
Www.mysql.com/downloads/looking for connectors, and then connector/j click on the left side of the page will appear for the selection of tar.gz and zip file download Download. tar.gz file

2. Expand the file you just downloaded (mysql-connector-java-5.0.6.tar.gz)
Tar zxvf mysql-connector-java-5.0.6.tar.gz

3. Configure the Connection file
Copy the Mysql-connector-java-5.0.6-bin.jar file from the mysql-connector-java-5.0.6 you just expanded to the JDK installed above and the Lib folder under Tomcat

    1. CD mysql-connector-java-5.0.6
    2. CP./mysql-connector-java-5.0.6-bin.jar ~/jdk/lib
    3. CP./mysql-connector-java-5.0.6-bin.jar ~/tomcat/lib

4. In the process of writing Ubuntu JSP platform, the connection database can be in the following format:

  1. Class.forName ("Com.mysql.jdbc.Driver"). newinstance ();
  2. Connection Conn = drivermanager. getconnection ("jdbc:mysql://localhost/database name", "username", "password")  ;
  3. Statement stmt = conn. createstatement (Resultset.type_scroll_sensitive, Resultset.concur_  updatable);
  4. String SQL = "SELECT * from database name";
  5. ResultSet rs = stmt. executeQuery (SQL);

Seven. Testing

Sudo-shpassword start MySQL service: #/etc/init.d/mysql start Tomcat Service: #/home/tomcat/bin/startup.sh Create a Test database and table: #/mysql-u Root-ppassword

  2. MySQL> use test;
  3. MySQL> CREATE TABLE Test (test1 varchar, test2 varchar (20));
  4. MySQL> INSERT INTO Test (TEST1,TEST2) VALUES (' A ', ' B ');
  5. Check if test information has been added
  6. MySQL> show Databases;
  7. MySQL> show Tables;
  8. MySQL> select * from test;

Create a new empty file under/home/jinye/tomcat/webapps/root, named Test. Ubuntu JSP platform, writing code
The test program code is as follows:

  1. <%@ page c%>
  2. <%@ page Import="java.util.*"%>
  3. <%@ page Import="java.sql.*"%>
  4. <%class.forname ("Com.mysql.jdbc.Driver"). newinstance ();
  5. Connection Conn = drivermanager. getconnection ("Jdbc:mysql://localhost/test", "Root", "  666nnn ");
  6. Statement stmt = conn. createstatement (Resultset.type_scroll_sensitive, Resultset.concur_  updatable);
  7. String SQL = "SELECT * from Test";
  8. ResultSet rs = stmt. executeQuery (SQL);
  9. while (Rs.next ()) {%>
  1. Your first field content is:<%=rs.getstring (1)%>
  2. Your second field content is:<%=rs.getstring (2)%>
  3. <%}%>
  4. <%out.print ("Successful database operation, congratulations");%>
  5. <% rs.close ();
  6. Stmt.close ();
  7. Conn.close ();
  8. %>

Open the Firefox browser and enter the URL: Http://localhost:8080/test.Ubuntu JSP platform See the information in the test table that you just created on the command line.

"Editor's recommendation"

      1. Ubuntu kernel devices are implicitly mapped to the/dev directory
      2. Ubuntu Apache configuration installation and ROR application
      3. Ubuntu CVS can be updated with the latest version of the code
      4. All kinds of weird things about the Ubuntu installation environment
      5. Ubuntu Apache installs the famous open source HTTP service side

Ubuntu JSP platform uses JDBC to connect to MySQL database

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.