内部异常:java.sql。SQLException异常:没有选择数据库

时间:2022-11-25 22:52:12

I know this question is very common among persistence users. I've visited so many the threads and questions on so many forums and still I'm not getting solution.

我知道这个问题在持久性用户中很常见。我在很多论坛*问了那么多的帖子和问题,但我还是没有找到解决方案。

I've created RESTful web services from database (an option in Netbeans 8.0.2). I've also created connection pool and JNDI for this project. Names are properly given as shown here.

我已经从数据库(Netbeans 8.0.2中的一个选项)创建了RESTful web服务。我还为这个项目创建了连接池和JNDI。名称按此处所示正确地给出。

Using EclipseLink (JPA 2.1) i.e by default I'm getting this kind of response:

使用EclipseLink (JPA 2.1) i。e默认情况下我会得到这样的回答:

GET RequestFailed RequestFailed --> Status: (500) Response: { HTTP Status 500 - Internal Server Error

GET RequestFailed——> Status: (500) Response: {HTTP Status 500 - Internal Server Error

type Exception report

类型异常报告

messageInternal Server Error

messageInternal服务器错误

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

服务器遇到了一个内部错误,导致它无法完成这个请求。

exception

异常

javax.servlet.ServletException: javax.ejb.EJBException

javax.servlet。ServletException:javax.ejb.EJBException

root cause

根本原因

javax.ejb.EJBException

javax.ejb.EJBException

root cause

根本原因

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: No database selected Error Code: 1046 Call: SELECT id, access_expires, access_token, address, bank_account_type, created, device_id, device_type, email, facebook_id, grazie_code, latitude, longitude, password, phone_number, profile_pic, refresh_expires, refresh_token, reg_id, token_created, total_balance, type_work, user_name, user_type FROM users Query: ReadAllQuery(referenceClass=Users sql="SELECT id, access_expires, access_token, address, bank_account_type, created, device_id, device_type, email, facebook_id, grazie_code, latitude, longitude, password, phone_number, profile_pic, refresh_expires, refresh_token, reg_id, token_created, total_balance, type_work, user_name, user_type FROM users")

javax.persistence。异常[EclipseLink-4002] (Eclipse持久性服务- 2.2.2.2.2.2.v20140319 -9ad6abd): org. eclipsee . Persistence . Exception。DatabaseException内部例外:java.sql。调用:选择id, access_expires, access_token,地址,bank_account_type,创建,device_id, device_type, email, facebook_id, grazi_code,经度,密码,phone_number, profile_pic, refresh_expiresreadallwork查询(referenceClass=Users sql="SELECT id, access_expires, access_token, address, address, bank_account_type, created, device_id, device_type, email, facebook_id, grazie_code, latitude, password, phone_number, profile_pic, refresh_expires, expires, device_id,

root cause

根本原因

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: No database selected Error Code: 1046 Call: SELECT id, access_expires, access_token, address, bank_account_type, created, device_id, device_type, email, facebook_id, grazie_code, latitude, longitude, password, phone_number, profile_pic, refresh_expires, refresh_token, reg_id, token_created, total_balance, type_work, user_name, user_type FROM users Query: ReadAllQuery(referenceClass=Users sql="SELECT id, access_expires, access_token, address, bank_account_type, created, device_id, device_type, email, facebook_id, grazie_code, latitude, longitude, password, phone_number, profile_pic, refresh_expires, refresh_token, reg_id, token_created, total_balance, type_work, user_name, user_type FROM users")

异常[EclipseLink-4002] (Eclipse持久性服务- 2.2.2.2.2.2.v20140319 -9ad6abd): org. eclipsee . Persistence . Exception。DatabaseException内部例外:java.sql。SQLException:没有数据库选择的错误代码:1046调用:选择id、access_expires、access_token、address、bank_account_type、创建、device_id、device_type、email、facebook_id、grazie_code、latitude、经度、密码、phone_number、profile_pic、refresh_expires、refresh_token、reg_id、token_create、total_balance、type_work、user_name、user_type FROM users查询:ReadAllQuery(referenceClass=Users sql="SELECT id, access_expires, access_token, address, bank_account_type,创建,device_id, device_type, email, facebook_id, grazie_code, latitude, longitude, password, phone_number, profile_pic, refresh_expires, refresh_token, reg_id, token_create, total_balance, type_work, user_name, user_type FROM Users ")

root cause

根本原因

java.sql.SQLException: No database selected

java.sql。SQLException异常:没有选择数据库

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1 logs. GlassFish Server Open Source Edition 4.1

注意,在GlassFish服务器的开放源码版本4.1日志中可以找到异常及其根源的完整堆栈跟踪。GlassFish服务器开源版本4.1

my persistence.xml file is like this:

我的坚持。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="dwolla_apiPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/dwolla</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>ALL</shared-cache-mode>
    <properties>
        <property name="eclipselink.target-database" value="MySQL"/>
        <property name="eclipselink.logging.logger" value="DefaultLogger"/>
        <property name="eclipselink.ddl-generation" value="create-tables"/>
        <property name="eclipelink.logging.level" value="FINEST"/>
        <!-- JDBC connection properties -->
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/dwolla"/>
        <property name="javax.persistence.jdbc.user" value="root"/>
        <property name="javax.persistence.jdbc.password" value=""/>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
        <property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
        <property name="javax.persistence.schema-generation.database.action" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

Domain.xml:

Domain.xml:

<resources>
    <jdbc-resource pool-name="__TimerPool" jndi-name="jdbc/__TimerPool" object-type="system-admin" />
    <jdbc-resource pool-name="DerbyPool" jndi-name="jdbc/__default" object-type="system-all" />
    <jdbc-resource pool-name="APIConnectionPool" jndi-name="jdbc/dwolla" object-type="user" />
    <jdbc-connection-pool name="__TimerPool" datasource-classname="org.apache.derby.jdbc.EmbeddedXADataSource" res-type="javax.sql.XADataSource">
        <property value="${com.sun.aas.instanceRoot}/lib/databases/ejbtimer" name="databaseName" />
        <property value=";create=true" name="connectionAttributes" />
    </jdbc-connection-pool>
    <jdbc-connection-pool is-isolation-level-guaranteed="false" name="DerbyPool" datasource-classname="org.apache.derby.jdbc.ClientDataSource" res-type="javax.sql.DataSource">
        <property value="1527" name="PortNumber" />
        <property value="APP" name="Password" />
        <property value="APP" name="User" />
        <property value="localhost" name="serverName" />
        <property value="sun-appserv-samples" name="DatabaseName" />
        <property value=";create=true" name="connectionAttributes" />
    </jdbc-connection-pool>
    <jdbc-connection-pool is-isolation-level-guaranteed="false" name="APIConnectionPool" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" res-type="javax.sql.DataSource">
        <property name="URL" value="jdbc:mysql://localhost:3306/dwolla"/>
        <property value="3306" name="PortNumber" />
        <property value="" name="Password" />
        <property value="root" name="User" />
        <property value="localhost" name="serverName" />
        <property value="dwolla" name="DatabaseName" />
        <property value=";create=true" name="connectionAttributes" />
    </jdbc-connection-pool>
</resources>
<servers>
    <server name="server" config-ref="server-config">
        <resource-ref ref="jdbc/__TimerPool" />
        <resource-ref ref="jdbc/__default" />
        <resource-ref ref="jdbc/dwolla" />
    </server>
</servers>

2 个解决方案

#1


2  

I got the solution.As you can see I've edited domain.xml of glassfish server and set the connection pool properties and JNDI. I went to glassfish admin console and edited the connection pool, I get that the server is not recognizing the changes I did. It was showing the URL property like "jdbc:mysql://:3306/", don't know why it didn't get the properties from domain.xml but finally now it is working.

我得到了解决方案。如您所见,我已经编辑了域。glassfish服务器的xml,并设置连接池属性和JNDI。我去了glassfish管理控制台并编辑了连接池,我发现服务器没有识别我所做的更改。它显示了URL属性,比如“jdbc:mysql:/:3306/”,不知道为什么它没有从域获取属性。但现在它终于开始工作了。

#2


1  

To correct this error, go to glassfish admin console, proceed to JNDI>Additional properties tab.

要纠正这个错误,请转到glassfish管理控制台,转到JNDI>附加属性选项卡。

Under the Name column, confirm if the user,password,URL are correct if not edit the values accordingly.

在Name列下,确认用户、密码、URL是否正确,如果不相应地编辑值。

Edit URL to jdbc:mysql://localhost/{database}

编辑jdbc URL:mysql:/ / localhost / {数据库}

Note that {database} is your database name. Save the changes and test.

注意,{database}是您的数据库名。保存更改和测试。

内部异常:java.sql。SQLException异常:没有选择数据库

#1


2  

I got the solution.As you can see I've edited domain.xml of glassfish server and set the connection pool properties and JNDI. I went to glassfish admin console and edited the connection pool, I get that the server is not recognizing the changes I did. It was showing the URL property like "jdbc:mysql://:3306/", don't know why it didn't get the properties from domain.xml but finally now it is working.

我得到了解决方案。如您所见,我已经编辑了域。glassfish服务器的xml,并设置连接池属性和JNDI。我去了glassfish管理控制台并编辑了连接池,我发现服务器没有识别我所做的更改。它显示了URL属性,比如“jdbc:mysql:/:3306/”,不知道为什么它没有从域获取属性。但现在它终于开始工作了。

#2


1  

To correct this error, go to glassfish admin console, proceed to JNDI>Additional properties tab.

要纠正这个错误,请转到glassfish管理控制台,转到JNDI>附加属性选项卡。

Under the Name column, confirm if the user,password,URL are correct if not edit the values accordingly.

在Name列下,确认用户、密码、URL是否正确,如果不相应地编辑值。

Edit URL to jdbc:mysql://localhost/{database}

编辑jdbc URL:mysql:/ / localhost / {数据库}

Note that {database} is your database name. Save the changes and test.

注意,{database}是您的数据库名。保存更改和测试。

内部异常:java.sql。SQLException异常:没有选择数据库