facebook

Reload this Page Mysql Tomcat java.sql.SQLException

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #304455 Reply

    logixplayer
    Member

    I am having a trivial issue!
    I am using JPA and Spring to connect to my MySQL database.
    It work’s great within eclipse. However when I deploy it to tomcat it complains that it cannot read the password. As a result my JPA entityManagerFactory cannot be instantiated.

    
    WARNING: Could not obtain connection metadata
    java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
        at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3996)
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2142)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:781)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:284)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:154)
        at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
        at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2090)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2086)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1311)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:132)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:224)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:291)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:850)
        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:724)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:493)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:516)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    5-Dec-2009 8:24:38 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
    INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1ac3379: defining beans [entityManagerFactory,transactionManager,sessionFactory,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,UserDAO,AttributesDAO,ProfileDAO,CommentDAO,CategoryDAO,TopicDAO,SubmissionDAO,iAttributesService,iCategoryService,iTopicService,iUserService,iSubmissionService,iProfileService]; root of factory hierarchy
    5-Dec-2009 8:24:38 PM org.springframework.web.context.ContextLoader initWebApplicationContext
    SEVERE: Context initialization failed
    

    I know I am using the right password because I can login through my MySQL client and observe my tables!

    Here is my persistence.xml that is relevant:

    
        <properties>
                <!-- <property name="dialect" value="org.hibernate.dialect.MySQLDialect" /> -->
                <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
                <property name="hibernate.connection.username" value="root" />
                <property name="hibernate.connection.password" value="mypassword" />
                <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/pf" />
                <property name="hibernate.show_sql" value="true" />
            </properties>
        </persistence-unit>
    </persistence>
    

    Even though the password is there, it’s like it’s not being read.
    Any help would be appreciated. Thank you!

    #304459 Reply

    logixplayer,

    java.sql.SQLException: Access denied for user ‘root’@’localhost’ (using password: NO)

    This could be an issue with MySql. Can you refer to the following link –
    http://www.coderanch.com/t/306302/JDBC/java/Access-denied-user-root-localhost
    Let me know if that helps

    #304488 Reply

    logixplayer
    Member

    hi,
    I have checked my permissions in the user table. I only have one user, root.
    In the Users table, here are my values:
    host : localhost
    user: root
    password: *81F5E23E35407D894A6CD4J731AEBFB6AF209E1B

    This root user is the default user created when I installed mySQL. They have a “Y” for every field…so I assume this means
    full permissions AND it looks like they are permitted to use host=localhost?
    I noticed one thing from before even,

    INFO: connection properties: {user=root, autocommit=true, release_mode=auto}

    It never reads my password in the connection properties! which is why mySQL is complaining that there is no password.
    I have however included my password in my persistence.xml file.

    
    INFO: Using Hibernate built-in connection pool (not for production use!)
    7-Dec-2009 9:12:15 PM org.hibernate.connection.DriverManagerConnectionProvider c
    onfigure
    INFO: Hibernate connection pool size: 20
    7-Dec-2009 9:12:15 PM org.hibernate.connection.DriverManagerConnectionProvider c
    onfigure
    INFO: autocommit mode: true
    7-Dec-2009 9:12:15 PM org.hibernate.connection.DriverManagerConnectionProvider c
    onfigure
    INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/pf
    
    7-Dec-2009 9:12:15 PM org.hibernate.connection.DriverManagerConnectionProvider c
    onfigure
    INFO: connection properties: {user=root, autocommit=true, release_mode=auto}
    7-Dec-2009 9:12:15 PM org.hibernate.cfg.SettingsFactory buildSettings
    WARNING: Could not obtain connection metadata
    java.sql.SQLException: Access denied for user 'root'@'localhost' (using password
    : NO)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
    

    Any clues? Please advise.
    Thanks

    #304500 Reply

    logixplayer,
    I just verified the password given in the above post (*81F5E23E35407D894A6CD4J731AEBFB6AF209E1B) against the password i have for
    root. The above password corresponds to “root”. But the password in your persistence.xml is “mypassword”.
    It could be possible that the password is not reset correctly
    Please reset your password as mentioned in the below link and let me know if that works
    http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

    #304946 Reply

    logixplayer
    Member

    This message has not been recovered.

    #304948 Reply

    This message has not been recovered.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Reload this Page Mysql Tomcat java.sql.SQLException

You must be logged in to post in the forum log in