从jdk安装到jsp连接oracle数据库的相关配置
2009-12-31 15:34
686 查看
1.安装jdk(版本6u7);
2.配置jdk环境变量(安装目录:D:/tools/java/jdk1.6.0_07):
1). JAVA_HOME = D:/tools/java/jdk1.6.0_07;
2). Path的最前面追加"D:/tools/java/jdk1.6.0_07/bin;D:/tools/java/jre1.6.0_07/bin";
3). CLASSPATH = D:/tools/java/jdk1.6.0_07/lib;D:/tools/java/jdk1.6.0_07/lib/tools.jar;
3.安装 tomcat(版本6.0.20)
4.配置tomcat环境变量(安装目录:D:/tools/tomcat6.0)
1).CATALINA_HOME=D:/tools/tomcat6.0;
2).CATALINA_BASE=D:/tools/tomcat6.0;
3).CLASSPATH后面追加"%CATALINA_HOME%/lib/servlet-api.jar;"
5.安装oracle数据库(版本10g)
数据库名:orcl
用户名:mydata
密码:oracle
6.配置tomcat与oracle的连接
1).D:/tools/tomcat6.0/conf/server.xml追加如下内容:
<Context path="/test" reloadable="true" docBase="D:/tools/tomcat6.0/webapps/test" debug="0" >
<Resource name="jdbc/oracle" auth="Container" type="javax.sql.DataSource"
maxActive="5" maxIdle="4" maxWait="10000"
username="mydata" password="oracle" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL"/>
</Context>
说明:①、path="/test"(/test为tomcat中webapps目录下的工程文件夹)
②、docBase="D:/tools/tomcat6.0/webapps/test"(path中工程文件夹所在的绝对路径)
③、username="mydata"(oracle数据库的用户名)
④、password="oracle"(oracle数据库的密码)
⑤、url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL"/>(ORCL为oracle数据库名)
2).
在D:/tools/tomcat6.0/lib文件夹里放入oracle驱动文件ojdbc14.jar(此文件可在网上下载)
3).在webapps下新建工程文件夹test,在test文件夹下新建WEB-INF文件夹和test.jsp文件;
在WEB-INF文件夹下新建lib文件夹和web.xml文件;在lib文件夹下放入oracle驱动文件
ojdbc14.jar(此文件可在网上下载)
web.xml文件内容如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/oracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
test.jsp文件内容如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/oracle");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery("select stuAge from students");
while (rst.next()) {
out.println(rst.getInt(1));
}
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
%>
7.打开网页http://localhost:8080/test/test.jsp
2.配置jdk环境变量(安装目录:D:/tools/java/jdk1.6.0_07):
1). JAVA_HOME = D:/tools/java/jdk1.6.0_07;
2). Path的最前面追加"D:/tools/java/jdk1.6.0_07/bin;D:/tools/java/jre1.6.0_07/bin";
3). CLASSPATH = D:/tools/java/jdk1.6.0_07/lib;D:/tools/java/jdk1.6.0_07/lib/tools.jar;
3.安装 tomcat(版本6.0.20)
4.配置tomcat环境变量(安装目录:D:/tools/tomcat6.0)
1).CATALINA_HOME=D:/tools/tomcat6.0;
2).CATALINA_BASE=D:/tools/tomcat6.0;
3).CLASSPATH后面追加"%CATALINA_HOME%/lib/servlet-api.jar;"
5.安装oracle数据库(版本10g)
数据库名:orcl
用户名:mydata
密码:oracle
6.配置tomcat与oracle的连接
1).D:/tools/tomcat6.0/conf/server.xml追加如下内容:
<Context path="/test" reloadable="true" docBase="D:/tools/tomcat6.0/webapps/test" debug="0" >
<Resource name="jdbc/oracle" auth="Container" type="javax.sql.DataSource"
maxActive="5" maxIdle="4" maxWait="10000"
username="mydata" password="oracle" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL"/>
</Context>
说明:①、path="/test"(/test为tomcat中webapps目录下的工程文件夹)
②、docBase="D:/tools/tomcat6.0/webapps/test"(path中工程文件夹所在的绝对路径)
③、username="mydata"(oracle数据库的用户名)
④、password="oracle"(oracle数据库的密码)
⑤、url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL"/>(ORCL为oracle数据库名)
2).
在D:/tools/tomcat6.0/lib文件夹里放入oracle驱动文件ojdbc14.jar(此文件可在网上下载)
3).在webapps下新建工程文件夹test,在test文件夹下新建WEB-INF文件夹和test.jsp文件;
在WEB-INF文件夹下新建lib文件夹和web.xml文件;在lib文件夹下放入oracle驱动文件
ojdbc14.jar(此文件可在网上下载)
web.xml文件内容如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/oracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
test.jsp文件内容如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/oracle");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery("select stuAge from students");
while (rst.next()) {
out.println(rst.getInt(1));
}
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
%>
7.打开网页http://localhost:8080/test/test.jsp
相关文章推荐
- JSP连接MS SQL Server2000安装配置
- CentOS 安装配置JDK与Tomcat支持jsp文件解析
- 菜鸟:只安装和配置instantclient,用plsql developer,navicat for oracle,sqlplus连接oracle数据库
- Linux(Rhat&CentOS)安装JDK及相关配置
- mac下配置jsp开发环境——jdk安装及配置
- JSP运行环境的安装与配置--JDK+TOMCAT
- Eclipse连接Oracle数据库的具体步骤-安装配置
- jsp环境的配置-jdk(1.6)和tomcat6.0-第二步 tomcat 6.0 的安装
- 在C#中,远程连接Oracle数据库(不安装客户端,无需多余配置)
- Linux 下安装JDK,并配置相关环境变量
- 不安装客户端oracle客户端 Nhibernate配置连接oracle数据库
- PowerDesigner的安装及配置连接Oracle数据库
- JSP连接Mysql的数据库连接池配置相关
- mac 安装jdk/maven/tomcat 以及eclipse相关配置
- PL/SQL远程连接Oracle数据库相关配置
- 如何配置JSP环境(安装JDK和TOMCAT服务器)
- pl/sql配置连接远程数据库oracle,本地没有安装oracle数据库的情况下
- 最简单的Jsp环境配置及数据库连接调试(Jdk7+Tomcat7+Mysql5.5)
- JDK的下载安装及其相关配置
- pl/sql配置连接远程数据库oracle,本地没有安装oracle数据库的情况下