O que estou fazendo errado pois estou tentando acessar o jndi
via TOMCAT 6 via eclipse usando um main ??? está certo pra fazer um teste.
o que fiz :
- alterei o arquivo context.xml no diretório conf do TOMCAT 6
- copiei o jar Oracle para diretorio lib do TOMCAT
- start no Servideo TOMCAT 6
- no eclipse rodei o main abaixo e deu o erro
import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class ConectaJNDI {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
InitialContext ctx = new InitialContext();
try{
DataSource db = (DataSource)ctx.lookup("java:comp/env/jdbc/bdteste");
Connection con = db.getConnection();
}catch(Exception e){
System.out.println("Erro="+e);
}
}
Erro=javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
<?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 -->
<WatchedResource>WEB-INF/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/bdteste"
type="javax.sql.DataSource"
username="des"
password="des"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@333.1.30.247:1521:xxxxx"
maxActive="10"
maxIdle="4"/>
</Context>