oracle以datasource数据源方式配置jdbc遇到的问题
2017-12-28 22:12
423 查看
(1)Name jdbc is not bound in this Context错误https://wenku.baidu.com/view/bd59cc47e518964bcf847cc3.html
https://stackoverflow.com/questions/12928030/javax-naming-namenotfoundexception-name-jdbc-eswastha-is-not-bound-in-this-co
(2)The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
最终配置是
web.xml中添加:
在META-INF文件夹新建context.xml
(3)tomcat的conf/context.xml
(4)tomcat的lib文件夹添加ojdbc8.jar
(5)最后写一个jsp文件测试:
https://stackoverflow.com/questions/12928030/javax-naming-namenotfoundexception-name-jdbc-eswastha-is-not-bound-in-this-co
(2)The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
最终配置是
web.xml中添加:
<resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/jdbc-test</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
在META-INF文件夹新建context.xml
<?xml version="1.0" encoding="UTF-8"?> <Context> <Resource name="jdbc/jdbc-test" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:orcl" username="c##zyx" password="root" maxActive="2" maxIdle="1" removeAbandoned="true" maxWait="300" /> </Context>
(3)tomcat的conf/context.xml
<?xml version='1.0' encoding='utf-8'?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You 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. --> <!-- The contents of this file will be loaded for each web application --> <Context> <!-- Default set of monitored resources. If one of these changes, the --> <!-- web application will be reloaded. --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as webapp lifecycle) --> <!-- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> --> <Resource name="jdbc/jdbc-test" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:orcl" username="c##zyx" password="root" maxActive="2" maxIdle="1" removeAbandoned="true" maxWait="300" /> <!--autoReconnect="true" failOverReadOnly="false" maxReconnects="10"--> </Context>
(4)tomcat的lib文件夹添加ojdbc8.jar
(5)最后写一个jsp文件测试:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="java.sql.*, javax.sql.*, javax.naming.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> test <% DataSource ds = null; Connection conn = null; ResultSet result = null; Statement stmt = null; ResultSetMetaData rsmd = null; try { Context context = new InitialContext(); /*Context envCtx = (Context) context.lookup("java:comp/env"); ds = (DataSource)envCtx.lookup("jdbc/jdbc-test");*/ ds = (DataSource) context.lookup("java:comp/env/jdbc/jdbc-test"); if (ds != null) { conn = ds.getConnection(); stmt = conn.createStatement(); result = stmt.executeQuery("SELECT * FROM E8_USER"); } while(result.next()) { String username = result.getString("USERNAME"); String password = result.getString("PASSWORD"); out.println(username+" "+password); } } catch (SQLException e) { System.out.println("Error occurred " + e); } int columns = 0; try { rsmd = result.getMetaData(); columns = rsmd.getColumnCount(); } catch (SQLException e) { System.out.println("Error occurred " + e); } %> </body> </html>
相关文章推荐
- 配置多数据源(oracle)遇到的一些问题
- Tomcat配置数据源(JNDI方式)&JDBC(与Oracle的连接)
- struts配置数据源类型问题 type="org.apache.commons.dbcp.BasicDataSource"
- ASP.NET#LinqDataSource控件配置对象模型时遇到的问题
- linux下安装oracle 11g 时用netca配置listener遇到的问题
- java建立临时数据源DataSource:加载配置文件的方式
- tomcat 6.0.18+oracle11g配置数据源连接池遇到的问题
- spring 配置文件中datasource 从properties文件中获取mysql数据库连接参数遇到的问题
- 各种数据库(oracle、mysql、sqlserver等)在Spring中数据源的配置和JDBC驱动包 .
- 各种数据库(oracle、mysql、sqlserver等)在Spring中数据源的配置和JDBC驱动包
- 有关oracle遇到日期显示问题,导入导出,安装,卸载,修改listener配置文件,创建用户和表空间等的部分问题.
- jboss-as-7.1.1.Final 数据源 Oracle DataSource 配置
- 数据源 jdbc tomcat oracle 配置
- ASP.NET#LinqDataSource控件配置对象模型时遇到的问题
- Struts中配置oracle数据源及SID问题
- 遇到的问题:Cannot load JDBC driver class 'oracle.jdbc.OracleDriver'
- java程序使用纯JDBC方式操作SQLServer2005数据库(无需配置数据源)
- IIS配置遇到的问题——未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项。试图加载格式不正确的程序。
- tomcat 配置mysql 数据源遇到的问题
- win7 64位 ,安装配置cx_Oracle,遇到的一些问题及解决方法