Where do you put the Oracle's JDBC Thin Driver

2019-08-16 01:01发布

问题:

Where do you save the jdbc thin driver for Oracle? I have tried jre/lib/ext but my program, Crystal Reports keeps saying it can't find it. I figure I have saved it in the wrong place.

If I go to a command prompt and use:

C:\TEMP>java oracle.jdbc.OracleDriver

Oracle 11.2.0.3.0 JDBC 4.0 compiled with JDK6 on Fri_Aug_26_08:19:15_PDT_2011
Default Connection Properties Resource
Wed Oct 12 14:02:05 EDT 2011

So I know it is there.

edit: Since I could not get CR to work I tried a console app but it cannot find the driver:

package javaapplication1;


public class JavaApplication1 {

 public static void main (String[] args) throws Exception
  {
   Class.forName ("oracle.jdbc.OracleDriver");

   Connection conn = DriverManager.getConnection
     ("jdbc:oracle:thin:@myserver:1521:mysid", "myid", "mypass");
                        // @//machineName:port/SID,   userid,  password
   try {
     Statement stmt = conn.createStatement();
     try {
       ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
       try {
         while (rset.next())
           System.out.println (rset.getString(1));   // Print col 1
       } 
       finally {
          try { rset.close(); } catch (Exception ignore) {}
       }
     } 
     finally {
       try { stmt.close(); } catch (Exception ignore) {}
     }
   } 
   finally {
     try { conn.close(); } catch (Exception ignore) {}
   }
  }
}

edit: On my computer it is here:

C:\Program Files\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\win32_x86\jdk\jre\lib\ext

回答1:

Just put it in the application's runtime classpath. The file system paths covererd by the classpath depends on how you're executing the application.

Based on your question history I see that you're using JSP/Servlets, which thus means that it's a web application in flavor of a WAR file which runs in an appserver. In that case, the JAR file needs to go in webapp's own /WEB-INF/lib folder or in the appserver's own /lib folder.

If it were a plain vanilla Java application .class file with a main() method which is to be executed by java command, then you'd have to use the -cp (-classpath) argument to specify the runtime classpath. It takes a collection of (semi)colon separated disk file system paths.

If it were a JAR file, then it had to be specified in the Class-Path entry in JAR's /META-INF/MANIFEST.MF file. This can be relative to the java -jar command's working directory.

You should really avoid putting 3rd party libraries in JRE's /lib folder. This would potentially introduce classpath problems with all other existing applications which use the same JRE.