简体   繁体   中英

Cannot connect to database using JDBC on Glassfish3

Is there any way to check whether my Glassfish acctually see ojdbc6.jar ?

I'm working with Netbeans 7.2.1, with JSF 2, Glassfish 3.1.2 and Oracle 11g. I want to connecto to this database.

So first I need to create connection pool in my Glassfish. I open localhost:4848 set 5 things:

  1. Resource Type: javax.sql.DataSource
  2. Class name of the data source: oracle.jdbc.pool.OracleDataSource
  3. Property: "user"
  4. Property: "password"
  5. Property: "url"

Save, reset server (just for sure), ping.... and the error: Class name is wrong or classpath is not set for: oracle.jdbc.pool.OracleDataSource

What have I already done:

  1. First check for ojdbc jars. From my Oracle dir I copied every jar that has "ojdbc" in name into "C:\\glassfish3\\glassfish\\domains\\domain1\\lib".

  2. Second, check url properity. Inside Netbeans, switch into Services tab, right click on Databases, New connection... set data to connect (first I have to add, jodbc6.jar.. so I add exactly the same file - from glassfish folder). It works! connection is ok. I looked at Netbeans database url - the same as my url in glassfish gui. I also tried url with \\, but it didn't help.

So, what else can it be? Maybe no.1 is not ok. So this is my question: How can I check whether my Glassfish acctually see ojdbc6.jar?

EDIT. When I run Glassfish i get some warnings:

WARNING: Multiple [2] JMX MBeanServer instances exist, we will use the server at index [0] : [com.sun.enterprise.v3.admin.DynamicInterceptor@704d54].

WARNING: JMX MBeanServer in use: [com.sun.enterprise.v3.admin.DynamicInterceptor@704d54] from index [0]

WARNING: JMX MBeanServer in use: [com.sun.jmx.mbeanserver.JmxMBeanServer@ed312d] from index [1]

Copy all required jar files(ojdbc6.jar.....) to 'domains\\domain1\\lib\\ext' folder. Then restart your glassfish. Then try to ping from glassfish, it will work

"..But how do you know it is 'ext' folder? And not just 'lib'? One guy says lib, other ext.."

Making the JDBC Driver JAR Files Accessible To integrate the JDBC driver into a GlassFish Server domain, copy the JAR files into the domain-dir/lib directory, then restart the server. This makes classes accessible to all applications or modules deployed on servers that share the same configuration. For more information about GlassFish Server class loaders, see "Class Loaders" in GlassFish Server Open Source Edition Application Development Guide. If you are using an Oracle database with EclipseLink extensions, copy the JAR files into the domain-dir/lib/ext directory, then restart the server. For details, see "Oracle Database Enhancements" in GlassFish Server Open Source Edition Application Development Guide

From here

Note that when NetBeans runs glassfish on Windows, the "domains" directory it uses is in your home directory, not in C:\\glassfish or C:\\Program Files\\glassfish

On my windows 7, running NetBeans 8.0.2 with Glassfish 4.1, I had to put the Oracle driver jar (ojdbc6.jar) into

c:/Users/t823517/AppData/Roaming/NetBeans/8.0.2/config/GF_4.1/domain1

May be netbeans create virtual app if you run glassfish from IDE. Try this way of adding jars: http://netbeans.org/kb/docs/javaee/entappclient.html

Copy the ojdbc6-11.1.0.jar (the ojdbc6 version could be different in your case ) to glassfish_installation\\glassfish\\lib

Restart glassfish server

对于payara服务器我将ojdbc jar复制到{payara_installation_folder} \\ glassfish \\ lib,它的工作正常

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM