与this question类似的问题,但没有帮助。
我现在已经在亚马逊主机上的Jboss 6服务器上部署了h2。我正在使用以下详细信息来尝试连接
Connection conn = DriverManager.getConnection(
"jdbc:h2:~/test", "-user",
"");
我尝试了许多其他组合,包括上面链接的组合,并使用了教程中提供的详细信息,似乎没有任何效果。以下是堆栈跟踪。
org.h2.jdbc.JdbcSQLException: Wrong user name or password [28000-173]
org.h2.message.DbException.getJdbcSQLException(DbException.java:331)
org.h2.message.DbException.get(DbException.java:171)
org.h2.message.DbException.get(DbException.java:148)
org.h2.message.DbException.get(DbException.java:137)
org.h2.engine.Engine.validateUserAndPassword(Engine.java:302)
org.h2.engine.Engine.createSessionAndValidate(Engine.java:147)
org.h2.engine.Engine.createSession(Engine.java:122)
org.h2.engine.Engine.createSession(Engine.java:28)
org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:313)
org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:105)
org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:90)
org.h2.Driver.connect(Driver.java:73)
java.sql.DriverManager.getConnection(DriverManager.java:620)
java.sql.DriverManager.getConnection(DriverManager.java:200)
extension.Package.loadData(Package.java:477)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:616)
org.jboss.web.tomcat.service.TomcatInjectionContainer.processesLifecycleCallbackMetaData(TomcatInjectionContainer.java:560)
org.jboss.web.tomcat.service.TomcatInjectionContainer.postConstruct(TomcatInjectionContainer.java:333)
org.jboss.web.jsf.integration.injection.JBossDelegatingInjectionProvider.invokePostConstruct(JBossDelegatingInjectionProvider.java:90)
com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:219)
com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:101)
com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:405)
com.sun.faces.mgbean.BeanManager.create(BeanManager.java:265)
com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:191)
com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:73)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:71)
org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:67)
org.apache.el.parser.AstValue.getValue(AstValue.java:115)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:106)
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
javax.faces.component.UIOutput.getValue(UIOutput.java:164)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:201)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:351)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:160)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:879)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:308)
com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:181)
com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:125)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:849)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1643)
javax.faces.render.Renderer.encodeChildren(Renderer.java:164)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:849)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1643)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1646)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1646)
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:389)
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:127)
javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:269)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:117)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:135)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:309)
对于我出错的地方的任何帮助将不胜感激。 谢谢。
答案 0 :(得分:7)
我曾遇到过完全相同的问题:我无法访问基于H2文件的数据库。我从不为H2数据库指定任何密码用户。 当我遇到连接问题&#34;错误的用户名或密码&#34;时,已经存在上一次运行应用程序的现有文件。 删除现有的* .db文件解决了这个问题(我猜它是使用生成的用户/密码对创建的,自那以后已经改变了。)
答案 1 :(得分:4)
您的用户名是否真的“ - user”,密码是否为空字符串?您正在使用参数
调用方法DriverManager.getConnection(String url, String user, String password)
url = "jdbc:h2:~/test"
user = "-user"
password = ""
(空字符串)如果您希望用户名和密码都是空字符串,则有两个选项:
DriverManager.getConnection("jdbc:h2:~/test", "", "");
DriverManager.getConnection("jdbc:h2:~/test");