您的位置 首页 java

从jdk安装到jsp连接oracle数据库的相关配置

您可能感兴趣的话题: java  

核心提示:从jdk安装到jsp连接oracle数据库的相关配置。

  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();

  }

  %>

文章来源:智云一二三科技

文章标题:从jdk安装到jsp连接oracle数据库的相关配置

文章地址:https://www.zhihuclub.com/9140.shtml

关于作者: 智云科技

热门文章

网站地图