How to install the JSP in WINDOSWS 2000 and Access Oracle

Source: Internet
Author: User
Tags insert connect odbc query stmt zip tomcat oracle database
js|oracle| access to the system environment:
1, operating system: Windows 2000
2. Database: Oracle 8i R2 (8.1.6) for NT Enterprise Edition
3, Installation path: c:oracle
This example uses the software to download the address:
1, JDK-1_2_2_006-WIN.EXE[19.5MB]
Http://java.sun.com/products/jdk/1.2/
2, JAKARTA-TOMCAT.ZIP[2.26MB]
Http://jakarta.apache.org/builds/tomcat/release/v3.1/

Installation method:
First, install the JDK
The first step is to double-click the Jdk-1_2_2_006-win.exe file for installation and install using the default configuration
The default installation directory for JDK is the C:JDK1.2.2,JRE default installation directory for C:Program FilesJavaSoftJRE1.2;
Step two, update the environment variables
Start-> Setup-> Control Panel-> System-> Advanced-> Environment variable-> System variable
Append Classpath:c:/jdk1.2.2/lib/tools.jar;c:/jdk1.2.2/libdt.jar;
Append path:c:/jdk1.2.2;c:jdk1.2.2/bin;
Second, the installation of Tomcat
The first step is to extract the Jakarta-tomcat.zip into the C:jakarta-tomcat directory with WinZip
Step two, go to C:jakarta-tomcain directory, find startup.bat batch file, open edit
Row: Start with the following two lines:
SET Tomcat_home=c:jakarta-tomcat
SET java_home=c:jdk1.2.2

Step three, double-click Startup.bat to start the Tomcat server
At this point, a DOS window appears on the screen, stops motionless, and there are some running successful tomcat and initialization information,
proves that Tomcat is running successfully.

Step Fourth, enter http://localhost:8080/on the browser
If you can see the Tomcat Version 3.1 page, the Tomcat installation is successful.
There are some examples of JSP and servlet, the JSP environment is completed.
Note: The above Stop DOS window cannot be turned off, or the Tomcat server stops serving
Note: The JSP file runs slowly for the first time
Third, the first JSP example
Name the program test.jsp, and put it in the C:jakarta-tomcatwebappsexamples directory.
Enter http://localhost:8080/examples/test.jsp in Browser
<%
String Str = "Hello jsp!";
Out.print ("Hello jsp!");
%>
Iv. write the first JSP program to connect Oracle test.jsp
1, connect into the Sql*plus
Log in as a System/manager user,
Sql> Conn System/manager

Create a new user: such as USER1/PASS1, give Connect,resource permissions.
Sql> Grant Connect,resource to User1 identified by Pass1;

Sql> Conn User1/pass1
Sql> CREATE TABLE Test (a number,b char (10));
sql> INSERT INTO test values (1, ' one ');
sql> INSERT INTO test values (2, ' II ');
sql> INSERT INTO test values (3, ' three ');
Sql> commit;

Sql> select * from test;

A B
---------- ----------
11
22
33

2. Configure ODBC (set on server side)

Start-> Settings-> Control Panel-> Admin Tools-> Data Source (ODBC)-> System dsn-> Add->
Select Oracle ODBC Driver-> Complete->

Data Source name:test name, easy to remember on the line, such as: test
Service name:oradb The instance name of the Oracle database, in this example: ORADB, the general Oracle default installation is ORCL
Userid:user1 Oracle user name, in this case: User1

Press "OK"-> Press "OK" to exit


3, under C:jakarta-tomcatwebappsexamples create test.jsp, with notebook edit, enter the following code
<!--first import some of the necessary packages-->
<%@ page info= "Database handler"%>
<%@ page import= "java.io.*"%>
<%@ page import= "java.util.*"%>

<!--tell the compiler to use SQL package-->
<%@ page import= "java.sql.*"%>

<%@ page import= "javax.servlet.*"%>
<%@ page import= "javax.servlet.http.*"%>

<%
Start with try
Try
{
Connection con;
Statement stmt;
ResultSet rs;

Loading the driver, the following code is loading the JDBD-ODBC driver
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");

Connect to the database with the appropriate driver, test "is the System DSN name
String url= "Jdbc:odbc:test";

Establish a connection, similar to creating a database join in ASP
Con=drivermanager.getconnection (URL, "user1", "Pass1");

Create a JDBC Declaration
stmt = Con.createstatement ();

Add new record
Stmt.executeupdate ("INSERT into Test (a,b) VALUES (1, ' 2 ')");

Query records
rs = Stmt.executequery ("SELECT a,b from Test");

Output query Results
Out.println ("<table border=1 width=400>");
while (Rs.next ())
{
String col1 = rs.getstring (1);
String col2 = rs.getstring (2);
Print the data that is displayed
Out.println ("<tr><td>" +col1+ "</td><td>" +col2+ "</td></tr>");
}
Out.println ("</table>");
}

If an error occurs during loading, give the appropriate error message
catch (Exception e) {}
%>
4, open a browser window, enter the following address to view the results of the operation
http://localhost:8080/examples/test.jsp

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.