缺少数据源的驱动程序类名称(Netbeans+ PostgreSql + Glassfish)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23255426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The name of the driver class for the datasource is missing (Netbeans+ PostgreSql + Glassfish)
提问by albertosky86
I'm trying to develop an EJB application using Netbeans 8 on a Postgres 9.2 db and Glassfish 4 server.
我正在尝试在 Postgres 9.2 db 和 Glassfish 4 服务器上使用 Netbeans 8 开发 EJB 应用程序。
Once I created connection pool and JDBC resources in the glassfish admin panel, I'm not able to add entities using the datasource. Netbeans still giving me an error:
在 glassfish 管理面板中创建连接池和 JDBC 资源后,我无法使用数据源添加实体。Netbeans 仍然给我一个错误:
The name of the driver class for the datasource is missing
缺少数据源的驱动程序类名称
I've already tried adding libraries to the project. I copied postgresql-9.2-1002.jdbc4.jar and postgresql-9.2-1002.jdbc3.jar files in
C:\Program Files\glassfish-4.0\glassfish\domains\domain1\lib folder
.
我已经尝试将库添加到项目中。我将 postgresql-9.2-1002.jdbc4.jar 和 postgresql-9.2-1002.jdbc3.jar 文件复制到
C:\Program Files\glassfish-4.0\glassfish\domains\domain1\lib folder
.
Screenshot: http://imageshack.com/a/img843/6884/w3ko.png
截图:http: //imageshack.com/a/img843/6884/w3ko.png
If I create entities using a connection created before(in NB Services/Databases), it works, but result set after any query is empty. Any idea?
如果我使用之前创建的连接(在 NB 服务/数据库中)创建实体,它可以工作,但任何查询后的结果集为空。任何的想法?
Here the connection pool I created: http://imageshack.com/a/img838/8286/bkw8.png
这里是我创建的连接池:http: //imageshack.com/a/img838/8286/bkw8.png
This is my persistence.xml:
这是我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="Esempio-ejbPU" transaction-type="JTA">
<jta-data-source>try_</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
采纳答案by albertosky86
Solved: it was a connection pool issue. Creating a driver one in glassfish admin panel I've got no more problems.
已解决:这是一个连接池问题。在 glassfish 管理面板中创建一个驱动程序我再也没有问题了。
回答by Iragi KNJ
Apologies for being straightforward, but I believe that on this specific situation, you are all wrong. What should be done is:
恕我直言,但我相信在这种特定情况下,你们都错了。应该做的是:
- Go to your Glassfish server administration panel (Link should look like this: http://localhost:4848/common/index.jsf(Under Additional Properties tab)
- Click on Servicesin Netbeans
- Click on Server
- Right-click on your server name [A pop-up contextual menu appears]
- Click on View Domain Admin Console [Note: Your server must be running in order to see that feature. A browser tab is automatically launched, if the server is running. You know that your server is running if you see a greenish arrow pointing to the right on the right of the server instance]
- Click on resources
- Click on JDBC
- Click on JDBC Connection Pools
Add the following properties by clicking every time on the button Add Property (After selecting the pool name and editing it):
- driverClass: com.mysql.jdbc.Driver
- URL: jdbc:mysql://localhost/your_database_name
- password: your_password to the database management system
- serverName: localhost or your_server_name
- user: root or your_username to access the database management system
- databaseName: your_database_name
Set up your JDBC Resources [jdbc/your_pool_name]
- Point to the specific connection pool you just setup by selecting it in the drop down box.
- 转到您的 Glassfish 服务器管理面板(链接应如下所示:http://localhost:4848/common/index.jsf(在其他属性选项卡下)
- 单击Netbeans 中的服务
- 点击服务器
- 右键单击您的服务器名称 [弹出上下文菜单出现]
- 单击查看域管理控制台 [注意:您的服务器必须正在运行才能看到该功能。如果服务器正在运行,则会自动启动浏览器选项卡。如果您看到指向服务器实例右侧右侧的绿色箭头,则表示您的服务器正在运行]
- 点击资源
- 单击JDBC
- 单击JDBC 连接池
通过每次单击“添加属性”按钮添加以下属性(选择池名称并对其进行编辑后):
- 驱动程序类:com.mysql.jdbc.Driver
- URL: jdbc:mysql://localhost/your_database_name
- password: your_password 到数据库管理系统
- serverName: localhost 或 your_server_name
- user: root 或 your_username 访问数据库管理系统
- 数据库名称:your_database_name
设置您的JDBC 资源 [jdbc/your_pool_name]
- 通过在下拉框中选择它来指向您刚刚设置的特定连接池。
Save everything (The button usually is on the upper-right corner of your Internet browser) Don't forget that the JDBC Resources is always connected to a connection pool. So ensure that it is the case for you. They, JDBC Connection Pools and JDBC Resources, are usually located under JDBC in the left pane menu of your server administration panel. Go back to whatever you were doing, and try again. Please also note that this works for MySQL Database Management Systems. You might need to change the driver class as well as the URL if using another DBMS. You may find additional information on YouTube [http://www.youtube.com/].
保存所有内容(该按钮通常位于 Internet 浏览器的右上角) 不要忘记 JDBC 资源始终连接到连接池。因此,请确保您是这种情况。它们,JDBC 连接池和 JDBC 资源,通常位于服务器管理面板左窗格菜单中的 JDBC 下。回到你正在做的事情,然后再试一次。另请注意,这适用于 MySQL 数据库管理系统。如果使用另一个 DBMS,您可能需要更改驱动程序类以及 URL。您可以在 YouTube [ http://www.youtube.com/]上找到更多信息。
I believe this is the answer.
我相信这就是答案。
回答by Dale Moore
For me the issue was that I had added a new JDBC driver JAR file to Glassfish, but I hadn't added it to NetBeans.
对我来说,问题是我向 Glassfish 添加了一个新的 JDBC 驱动程序 JAR 文件,但我没有将它添加到 NetBeans。
The first step is to copy your JAR file to NetBean's EXT folder. For me, that folder is: "C:\Program Files\NetBeans 8.0.1\ide\modules\ext"
第一步是将 JAR 文件复制到 NetBean 的 EXT 文件夹。对我来说,那个文件夹是:“C:\Program Files\NetBeans 8.0.1\ide\modules\ext”
Next, we need to add the JDBC driver as described below:
接下来,我们需要添加 JDBC 驱动程序,如下所述:
- In NetBeans, select Window > Services menu option which adds the Services tab to the explorer panel.
- Expand the "Database" tree node
- Right click on the "Drivers" tree node and select "New Driver..."
- In the "New JDBC Driver" window press "Add..." which opens a dialog that says "Select Driver".
- Navigate to the EXT folder where you copied your JAR file and select the JAR file.
- Press OK.
- The new driver will be added to the list.
- 在 NetBeans 中,选择窗口 > 服务菜单选项,将服务选项卡添加到资源管理器面板。
- 展开“数据库”树节点
- 右键单击“驱动程序”树节点并选择“新建驱动程序...”
- 在“新建 JDBC 驱动程序”窗口中按“添加...”,这会打开一个显示“选择驱动程序”的对话框。
- 导航到复制 JAR 文件的 EXT 文件夹,然后选择 JAR 文件。
- 按确定。
- 新驱动程序将添加到列表中。
When I attempted to create an "Entity class from database", I still ran into issues when I selected my connection. After trying various things what worked for me was to:
当我尝试创建“来自数据库的实体类”时,在选择连接时仍然遇到问题。在尝试了各种事情后,对我有用的是:
- Open the Database tree node again and delete each of the database connections.
- Return to the Projects tabs and go through the steps to create an "Entity class from database".
- When the dialog appears, in the drop down select "New Data Source".
- Select the driver and then enter the information for your database.
- After recreating the connection I was able to create the Entity class from the selected database table.
- 再次打开数据库树节点并删除每个数据库连接。
- 返回到 Projects 选项卡并完成创建“来自数据库的实体类”的步骤。
- 当对话框出现时,在下拉列表中选择“新数据源”。
- 选择驱动程序,然后输入数据库的信息。
- 重新创建连接后,我能够从选定的数据库表创建实体类。
Good luck!
祝你好运!
回答by Akki
Steps in Netbeans:
Go To-->Service Tab-->Right Click on Drivers-->New Driver--> Add your driver jar file here
Steps in Netbeans:
Go To-->Service Tab-->Right Click on Drivers-->New Driver--> Add your driver jar file here
Netbeans automatically populates details of driver from JAR file.Check Driver Classvalue, this value we will use in Glassfish server connection pool.
Netbeans 自动从 JAR 文件中填充驱动程序的详细信息。检查驱动程序类值,我们将在 Glassfish 服务器连接池中使用该值。
Steps in Glassfish:
Steps in Glassfish:
Go to Glassfish Admin panel
In your JDBC Connection pool add property driverClass and paste the value of Driver Classregistered with Netbeans Drivers tab in previous step.
转到 Glassfish 管理面板
在您的 JDBC 连接池中添加属性 driverClass 并粘贴在上一步中使用 Netbeans Drivers 选项卡注册的Driver Class的值。
回答by Anr
I resolved this issue like this:
我这样解决了这个问题:
- Delete the datasource in glassfish.
- Create the connection datasource in Netbeans (Tab Services --> Databases)
- Create a Enterprise project
- Create Entity classes from Databases
- Execute the wizard
- Deploy the project in glassfish from NetBeans
- Enter to Glassfish Admin console and check the created datasource in Resources-->JDBC (Must be created a pool and datasource).
- 删除 glassfish 中的数据源。
- 在 Netbeans 中创建连接数据源(选项卡服务 --> 数据库)
- 创建企业项目
- 从数据库创建实体类
- 执行向导
- 从 NetBeans 在 glassfish 中部署项目
- 进入 Glassfish 管理控制台并在 Resources-->JDBC (必须创建池和数据源) 中检查创建的数据源。
回答by Hussein mahyoub
I faced the same problem, so:
我遇到了同样的问题,所以:
First of all, it's not Jboss or Glassfish problem. it's Netbeans or Eclipse.
Second to resolve that, do the below:
- Delete all connections (in Netbeans: from Services tab disconnect first then left click Delete)
- Recreate the connection again (in Netbeans: from Services tab then Database, left click New Connection. in the New Connection Wizard and after choosing the connection type, focus on JDBC URL and copy past from standalone. then Finish)
首先,这不是 Jboss 或 Glassfish 的问题。它是 Netbeans 或 Eclipse。
其次要解决这个问题,请执行以下操作:
- 删除所有连接(在 Netbeans 中:首先从服务选项卡断开连接,然后左键单击删除)
- 再次重新创建连接(在 Netbeans 中:从服务选项卡然后数据库,左键单击新建连接。在新建连接向导中,选择连接类型后,关注 JDBC URL 并从独立复制过去。然后完成)
回答by Ahmad Abdelghany
adding the driver jar file to "{$installation_folder}\NetBeans 8.0.1\ide\modules\ext" fixed the problem for me
将驱动程序 jar 文件添加到“{$installation_folder}\NetBeans 8.0.1\ide\modules\ext”为我解决了这个问题
回答by Jaf
In the connection pool properties, In the URL property don't forget "localhost"
在连接池属性中,在 URL 属性中不要忘记“localhost”
回答by Salman Muhammad
In my case I had to go to glassfish admin panel and change the driver class of Derby connection pool (under JDBC resources) to "org.apache.derby.jdbc.ClientDataSource"
在我的情况下,我必须转到 glassfish 管理面板并将 Derby 连接池的驱动程序类(在 JDBC 资源下)更改为“org.apache.derby.jdbc.ClientDataSource”