gpt4 book ai didi

java.sql.SQLException : Table/View 'LOCATION' already exists in Schema 'APP'

转载 作者:行者123 更新时间:2023-12-01 21:48:08 26 4
gpt4 key购买 nike

我正在 JBOSS EAP 6.2 中开发和部署 RESTful 服务。对于此任务,我使用 CXF、Spring 和 Embedded Derby 进行数据存储。我花了几个小时尝试调试这个错误,但无法实现。我已经检查过很多次数据库完全是空的并且没有任何表。但我总是收到相同的堆栈跟踪。我也读过类似的问题,但这也没有帮助。所以,代码如下:

资源类

package rest_3;

import java.sql.SQLException;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

@Path("/dataservice")
@Produces({"application/xml", "application/json"})
@Consumes({"application/xml", "application/json"})
public class DataService {

private ApplicationContext context = new ClassPathXmlApplicationContext("rest_3/servicebean.xml");
private DAO dao = (DAO) context.getBean("daoBean");

public DataService(DAO dao) {

}

@GET
@Path("/location/{id}")
public Location getLocation(@PathParam("id") int id) throws SQLException {
Location loc = dao.getLocation(id);
if (loc == null) {
ResponseBuilder builder = Response.status(Status.BAD_REQUEST);
builder.type("application/xml");
builder.entity("<error>Location Not Found</error>");
throw new WebApplicationException(builder.build());
}
return loc;
}

@POST
@Path("/location")
public Response addLocation(Location loc) throws SQLException {
if(loc == null)
return Response.status(Status.BAD_REQUEST).build();
dao.addLocation(loc);
return Response.ok().build();
}

@DELETE
@Path("/location/{id}")
public Response deleteLocation(@PathParam("id") int id) throws SQLException {
Location loc = dao.getLocation(id);
if(loc == null)
return Response.status(Status.BAD_REQUEST).build();
dao.deleteLocation(id);
return Response.ok().build();

}

@PUT
@Path("/location")
public Response updateLocation(Location loc) throws SQLException {
if(dao.getLocation(loc.getId()) == null)
return Response.status(Status.BAD_REQUEST).build();
dao.updateLocation(loc);
return Response.ok().build();
}

@DELETE
@Path("/location")
public void dropTable() throws SQLException {
dao.dropTable();
}


}

DAO 类

package rest_3;


import java.sql.*;

import org.apache.derby.jdbc.EmbeddedDataSource;

public class DAO {

private static Connection conn;
private static Statement statement;
private static PreparedStatement prep;

public DAO() throws SQLException {
this.load();
}

public void load() throws SQLException {

EmbeddedDataSource ds = new EmbeddedDataSource();
ds.setDatabaseName("derbyDB");
ds.setCreateDatabase("create");
conn = ds.getConnection();
statement = conn.createStatement();
statement.execute("create table location(id int, country varchar(40))");
statement.execute("insert into location values(1, 'MEXICO')");
statement.execute("insert into location values(2, 'SPAIN')");
statement.execute("insert into location values(3, 'UK')");
statement.execute("insert into location values(4, 'ITALY')");
statement.execute("insert into location values(5, 'JAPAN')");

}


public Location getLocation(int id) throws SQLException {
ResultSet rs = statement.executeQuery("select from location where id = " + id);
rs.next();
return new Location(rs.getInt("id"), rs.getString("country"));
}

public void addLocation(Location loc) throws SQLException{
int id = loc.getId();
String country = loc.getCountry();
prep = conn.prepareStatement("insert into location values(?,?)");
prep.setInt(1, id);
prep.setString(2, country);
prep.execute();
}

public void deleteLocation(int id) throws SQLException{
statement = conn.createStatement();
statement.executeUpdate("delete from location where id = " + id);

}

public void updateLocation(Location loc) throws SQLException {
int id = loc.getId();
String country = loc.getCountry();
statement = conn.createStatement();
statement.execute("update location set country = " + country + " where id = " + id);
}

public void dropTable() throws SQLException {
statement = conn.createStatement();
statement.execute("drop table location");
}

}

服务和 DAO bean。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="dataService" class="rest_3.DataService">
<constructor-arg ref ="daoBean"/>
</bean>

<bean id="daoBean" class="rest_3.DAO">
</bean>

</beans>

服务bean配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxrs:server id="DataService" address="/">
<jaxrs:features>
<cxf:logging/>
</jaxrs:features>
<jaxrs:serviceBeans>
<ref bean="dataService" />
</jaxrs:serviceBeans>
</jaxrs:server>
</beans>

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/beans.xml
classpath:rest_3/servicebean.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

堆栈跟踪:

16:28:05,892 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/rest_3]] (ServerService Thread Pool -- 47) JBWEB000287: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DataService': Cannot resolve reference to bean 'dataService' while setting bean property 'serviceBeans' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataService' defined in class path resource [rest_3/servicebean.xml]: Cannot resolve reference to bean 'daoBean' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoBean' defined in class path resource [rest_3/servicebean.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [rest_3.DAO]: Constructor threw exception; nested exception is java.sql.SQLException: Table/View 'LOCATION' already exists in Schema 'APP'.
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:287) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:126) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) [spring-beans-2.5.5.jar:2.5.5]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_79]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729) [spring-context-2.5.5.jar:2.5.5]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381) [spring-context-2.5.5.jar:2.5.5]
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) [spring-web-2.5.5.jar:2.5.5]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) [spring-web-2.5.5.jar:2.5.5]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) [spring-web-2.5.5.jar:2.5.5]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3339) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3777) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156) [jboss-as-web-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60) [jboss-as-web-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93) [jboss-as-web-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_79]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_79]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_79]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_79]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataService' defined in class path resource [rest_3/servicebean.xml]: Cannot resolve reference to bean 'daoBean' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoBean' defined in class path resource [rest_3/servicebean.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [rest_3.DAO]: Constructor threw exception; nested exception is java.sql.SQLException: Table/View 'LOCATION' already exists in Schema 'APP'.
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:495) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:162) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) [spring-beans-2.5.5.jar:2.5.5]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_79]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269) [spring-beans-2.5.5.jar:2.5.5]
... 31 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoBean' defined in class path resource [rest_3/servicebean.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [rest_3.DAO]: Constructor threw exception; nested exception is java.sql.SQLException: Table/View 'LOCATION' already exists in Schema 'APP'.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) [spring-beans-2.5.5.jar:2.5.5]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_79]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269) [spring-beans-2.5.5.jar:2.5.5]
... 46 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [rest_3.DAO]: Constructor threw exception; nested exception is java.sql.SQLException: Table/View 'LOCATION' already exists in Schema 'APP'.
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61) [spring-beans-2.5.5.jar:2.5.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877) [spring-beans-2.5.5.jar:2.5.5]
... 57 more
Caused by: java.sql.SQLException: Table/View 'LOCATION' already exists in Schema 'APP'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source) [derby-10.12.1.1.jar:]
at rest_3.DAO.load(DAO.java:25) [classes:]
at rest_3.DAO.<init>(DAO.java:15) [classes:]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_79]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_79]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_79]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [rt.jar:1.7.0_79]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100) [spring-beans-2.5.5.jar:2.5.5]
... 59 more
Caused by: ERROR X0Y32: Table/View 'LOCATION' already exists in Schema 'APP'.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.duplicateDescriptorException(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.addDescriptor(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.sql.execute.CreateTableConstantAction.executeConstantAction(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.sql.execute.MiscResultSet.open(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source) [derby-10.12.1.1.jar:]
at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source) [derby-10.12.1.1.jar:]
... 69 more

16:28:05,938 ERROR [org.apache.catalina.core] (ServerService Thread Pool -- 47) JBWEB001103: Error detected during context /rest_3 start, will stop it
16:28:05,938 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/rest_3]] (ServerService Thread Pool -- 47) Closing Spring root WebApplicationContext
16:28:05,938 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 47) MSC000001: Failed to start service jboss.web.deployment.default-host./rest_3: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./rest_3: org.jboss.msc.service.StartException in anonymous service: JBAS018040: Falló iniciar contexto
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:96)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_79]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_79]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_79]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_79]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: org.jboss.msc.service.StartException in anonymous service: JBAS018040: Falló iniciar contexto
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:161)
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60)
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93)
... 6 more

最佳答案

来自 setCreateDatabase() 的 Javadoc(强调我的):

Parameters:
create - if set to the string "create", this data source will try to create a new database of databaseName, or boot the database if one by that name already exists.

因此,第一次运行代码时,会创建数据库并创建表。第二次未重新创建数据库,并且创建表失败,因为它已经存在。

在 DAO 的构造函数中创建数据库和表确实是很糟糕的代码味道。如果您确实必须这样做,请确保在尝试创建数据库之前删除该数据库。如果这不适合您的设计,那么您刚刚发现了为什么在构造函数中创建数据库是一个坏主意。

关于java.sql.SQLException : Table/View 'LOCATION' already exists in Schema 'APP' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35663184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com