0
votes

Not a Java expert - in fact, working on a legacy project that will lead to a new project. That said, currently attempting to create the old project and connect to the test database. I can connect fine directly through Netbeans Services panel or through SQLDeveloper.

The server in use is currently Apache Tomcat 7.0.42.

The Oracle JDBC driver is ojdbc7.jar - I know, very old, but for the sake of getting the connection through this file was included in the source.

The Java platform is JDK 1.7, although that's the default for my copy of Netbeans - again, this is a very old project, I believe it was using DTD Web Application 2.3 so I may even be compiling with the wrong JDK, although I'm only seeing depreciation and restricted warnings I should be able to ignore (and they seem to lie more in the source packages and not in this aspect of the project.)

The project itself should have been working - I pulled it down through version control.

Since the source code contained no actual configuration for the JNDI I had to do my share of research (used to just regular MySQL data base connections; this world of JNDI is completely new to me.) - I ended up finding the following link which suggested modifying the server.xml (on Tomcat) and context.xml (of the web app). http://www.microdeveloper.com/html/JNDI_Orcl_Tomcat1p.html - although, that said, I'm not sure if this is the correct way to go about configuring the data source to begin with.

Server.XML

 <Resource name="jdbc/travel"
   aunt="Container"
   type="oracle.jdbc.pool.OracleDataSource"
   driverClassName="oracle.jdbc.OracleDriver"
   factory="oracle.jdbc.pool.OracleDataSourceFactory"
   url="jdbc:oracle:thin:@//dbname.host.com:1521/servicename.host.com"
   user="travel"
   password="password"
   maxActive="20"
   maxIdle="10"
   maxWait="-1"
 />

Context.xml

    <ResourceLink global="jdbc/travel" name="jdbc/travel" type="oracle.jdbc.pool.OracleDataSource"/>

Web.xml (not sure if needed)

<resource-ref>
   <description>Travel</description>
   <res-ref-name>jdbc/travel</res-ref-name>
   <res-type>oracle.jdbc.pool.OracleDataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>

I'm not exactly sure if I'm using type, auth, or factory correctly (also had to change driverClassName from the above link - when I tested the connection in NetBeans the properties listed oracle.jdbc.OracleDriver as the driver name.) To further my confusion, I'm not sure I understand why exactly the url contains // after the @ or how the service is working - but that will just require more research on my end. The schema I should be hitting is called travel (as is the username).

I can't necessarily include the classes actual initiating the connection due to the fact they're lengthy and call many other classes (different databases depending on configuration, different tools, schema, tables, etc.) I can include the method within my Jdbc class (log4j stuff omitted), however:

private transient Connection conn ;
private transient ResultSet rs ;
private transient Statement stmt ;
private transient Context initContext = null;
private DataSource ds = null;
private String jndiName = null;
public Jdbc( )
{
      super ( ) ;
} ;
public Jdbc( final String _jdniName ) throws TravelException , InstantiationException , IllegalAccessException , ClassNotFoundException
{
      super ( ) ;
      this.jndiName = _jdniName;
}
 public void connectToDatabase( ) throws TravelException
     {
          try
          {
               this.disconnectFromDatabase ( ) ;
               if (this.ds==null)
               {
                    this.initContext = new InitialContext();
                    Context envCtx = (Context) initContext.lookup("java:comp/env");
                    this.ds = (DataSource) envCtx.lookup(this.jndiName);
               }
               this.conn = this.ds.getConnection ( );
          }
          catch ( final Exception e )
          {
               this.conn=null ;
               throw new TravelException ( e ) ;
          }
 }

...

I'm not exactly sure if it's the environment causing the problem or my XML configuration - the error I keep hitting is :

 java.sql.SQLException: Io exception: Message file 'oracle.net.mesg.Message' is missing.

Which seems to point to an underlying issue that just isn't being reported - I'm assuming it's not actually connecting to the server.

If any more details is needed I'd be happy to provide what I can - my apologies if this sort of question doesn't fit the Stack Overflow M.O., as well - at my wit's end!

Just to summarize my issue - I'm having trouble connecting to an Oracle 10g DB through my code, however, I can connect fine directly using SQLDeveloper or the Services panel in Netbeans with the same URL and login information - I believe my issue lies in my configuration of the XML of the web application but I'm unsure where I'm going wrong. I do seem to get the same error message even when I no longer include the oracle jar in my compile-time libraries, as well, which is strange since I can see the jar in my Library folder in the IDE when it is included - oddly enough in my Tomcat folder it was nowhere to be found. Perhaps the issue is that the driver isn't being included correctly?

1

1 Answers

0
votes

Turns out this was an IDE issue - the JDBC driver wasn't being passed to the server as I stated above. I ended up taking down the server for good and shutting down Netbeans - from there I started up Eclipse and tested the application there in a different Tomcat instance - server booted up all fine. Shut that down and moved back to Netbeans; server was working.

IDEProblems