Java servlet+oracle Novice to see

Source: Internet
Author: User
Tags stmt java web tomcat server

Recently, the company leaders told the next product, may be related to Oracle database, previously used most of the MSSQL, the previous time to learn MySQL is a little used. Oracle has no contact. Should be for me to have done before. NET development, so the data access interface this piece, involves the ashx WCF webserver these, learned the next servlet to feel these techniques compared to the interface written by ASHX.

First, the Oracle database installed on the computer, the installation of Oracle database, it is common sense that the direct download of the installation is OK, but the middle of the problem, because my system is Win7 the client clients of Oracle does not support Win7 64, even 64 of the system is only I can download the 32-bit client installation, and here 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://

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 {        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.getconne Ction ("Jdbc:oracle:thin: @localhost: 1521:orcl", "SCOTT", "Lh19870426");//Create Connection stmt = Conn.createstatement ();//Create St Atement rs = stmt.executequery ("SELECT * from Oracletestdatabase");                Get result set while ( ()) {//Traverse result set Out.println ("<tr>"); Out.println ("<td>" + rs.getstring ("name") + "</td>");//Remove the column value out.println ("&LT;/tr> ");        } out.println ("</table>");        } catch (ClassNotFoundException e) {e.printstacktrace ();        } catch (SQLException e) {e.printstacktrace ();                    } finally {try {if (rs! = null) {rs.close ();                rs = null;                    } if (stmt! = null) {stmt.close ();                stmt= null;                    } if (conn! = null) {conn.close ();                conn = null;            }} catch (SQLException e) {e.printstacktrace (); }        }    }



Java servlet+oracle Novice to see

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: 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.