How to create Oracle DB connection via Java and Tomcat?
<p>I am trying to use Oracle DB via Java and Tomcat. 
The problem is that I can not configurate correct connection via connection pool and declaration in "server.xml" file. 
So, when I use this code in a Java class: </p>

<pre><code>Class.forName("oracle.jdbc.driver.OracleDriver"); 
Connection con =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:my","system","****"); 
String sql = "SELECT * FROM TestTable2"; 
PreparedStatement pStatement =con.prepareStatement(sql); 
ResultSet rs = pStatement.executeQuery(sql); 
</code></pre>

<p>Everything works fine. 
But when I use this code in a Java class: </p>

<pre><code>Context initContext = new 
InitialContext(); 
Context envContext = (Context)initContext.lookup("java:/comp/env"); 
DataSource datasource = (DataSource)envContext.lookup("jdbc/LocalMyDataBaseOracle"); 
Connection sqlCon = datasource.getConnection(); 

String sql = "SELECT * FROM TestTable2"; 
PreparedStatement pStatement =sqlCon.prepareStatement(sql); 

ResultSet rs = pStatement.executeQuery(sql); 
</code></pre>

<p>This code in  </p>

<pre><code>&lt;ResourceLink type="oracle.jdbc.pool.OracleDataSource" 
name="jdbc/LocalMyDataBaseOracle" 
global="jdbc/MyDataBaseOracle" 
/&gt; 
</code></pre>

<p>and this code in  </p>

<pre><code>&lt;Resource driverClassName="oracle.jdbc.driver.OracleDriver" 
factory="oracle.jdbc.pool.OracleDataSourceFactory" 
name="jdbc/MyDataBaseOracle" 
username="system" 
password="****" 
type="oracle.jdbc.pool.OracleDataSource" 
url="jdbc:oracle:thin:@localhost:1521:my" 

autoReconnectForConnectionPools="true" 
autoReconnectForPools="true" 
testOnBorrow="true" 
testWhileIdle="true" 
validationQuery="select 1 from dual" 
validationInterval="34" 
/&gt; 
</code></pre>

<p>I get an exception "java.sql.SQLException: ORA-01017: invalid username/password; logon denied" in line    <code>Connection sqlCon = datasource.getConnection();</code>    </p>

<p>The username and the password are the same in first and second codes. please advise what is going wrong ?</p>