Java servlet combined with Oracle to build Java Web development environment

Source: Internet
Author: User
Tags java web tomcat server

First, the Oracle database installed on the computer, the installation of Oracle database in common sense, the direct download of the installation is OK, but midway is a problem, because my system is Win7 the client clients of Oracle does not support Win7 64, Even 64 of the system can only download 32-bit client installation, where I reuse ghost to restore the next system. (In fact, it can be completely uninstalled later)

Second, my computer is always installed ecplise, but did not install the Java Web Development environment, below I say the installation method

Ecplise menu bar----help-->install New software

Then, in work with: text box on the left, enter: Http://download.eclipse.org/releases/kepler

Wait a moment after the Javaweb installation option appears: Then select the Last web ... Tick the next step.

Here our Javaweb development environment is installed, which contains the servlet .....

Third, then download the APACHE-TOMCAT server: I'm under 7, then unzip it to any path.

Iv. Creating a servlet environment

1: Open Ecplise

2: Create the APACHE-TOMCAT server (servlet will use, I will say the creation method)

Menu bar File----->new---->other---->server (Point open folder)--server then go directly to Next and select Apache point to select the corresponding version of the server you downloaded if you are 6. Several 7. A few of these versions are available in 6 or 7 ... next then select the folder path you just unzipped Apache-tomcat (below) in the browser of the.

3: Create Severlet

Menu bar File----->new---->other---->web-->dynamic WEB project Create and then go directly to next, after jumping to take a name to finish the following is

After creation: We need to create a. java file for the servlet I directly

When we get here, our servlet is created.

4: Run the servlet project we created

Java Resources--->SRC---> Package name---. java (servlet file) Right-click Run as

Check the list of servers: If this time the server status is stopped, we will need to restart the machine

Then the servlet can be started after the electric finish.

5: Import Oracle driver package Ojdbc14.jar do not know the path of direct input query, below

Above is the deployment assembly click Java Build Path entries after selecting the jar you just created to import

6: Connect the local Oracle database to query the data output of a table

protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {& Nbsp;            connection conn = null;         statement stmt = null;         ResultSet rs = null;        response.setcontenttype ("text/html");         response.setcharacterencoding ("gb2312");         printwriter out = Response.getwriter ();         Out.println ("<table border=1>");         out.println ("<tr> <td>Content:</td></tr> ");         try {                          class.forname ("Oracle.jdbc.driver.OracleDriver");//Load Driver             conn = Drivermanager.getconnection ("Jdbc:oracle:thin: @localhost: 1521:orcl", "SCOTT", "Lh19870426 ");//Create Connection           stmt = Conn.createstatement ();//Create statement             rs = Stmt.executequery ("SELECT * FROM Oracletestdatabase "); Get result set             while (Rs.next ()) {//traverse result set                  out.println ("<tr > ");                 Out.println ("<td>" + rs.getstring ("name") + "</td>");//Remove column values                  out.println ("</tr>");             }             out.println ("</table>");         } catch ( ClassNotFoundException e) {             E.printstacktrace ();         } catch (SQLException e) {             e.printstacktrace ();       &NBSP;&NBSP;} finally {            try {                 if (rs! = null) {                      Rs.close ();                     rs = null;                }                 if (stmt! = null) {                      stmt.close ();                     stmt= null;                 }             &NBSP;&NBSP;&NBSP;&NBSP;IF (conn! = null) {                     conn.close ();                     conn = null;                 }             } catch (SQLException e) {                 e.printstacktrace ();             }        }              }

Output:

Java servlet combined with Oracle to build Java Web development environment

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.