5 Replies Latest reply on Jul 26, 2009 12:01 PM by henrik kristiansen

    java.sql.SQLException: Access denied for user 'root'@'localhost'

    henrik kristiansen Newbie
      I'm using  jboss 5.0.1 GA and  a mysql 5.1 database.

      Mysql is running on port 3306
      I'm using the “root” user with “horsens” as password.

      I can log on the database from my console and from my IDE (IntelliJ) using the credentials, but when I deploy the project, I get the following error:

      15:42:18,906 WARN  [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
      org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES))

      I really hope someone can help, I have been stuck here for a couple of days.

      seam-gen.proterties:

      hibernate.connection.password=horsens
      workspace.home=C\:/Projects
      model.package=org.hison.model
      driver.jar=C\:\\Projects\\lib\\mysql.jar
      action.package=org.hison.action
      test.package=org.hison.test
      database.type=mysql
      richfaces.skin=blueSky
      hibernate.default_catalog.null=
      hibernate.default_schema.null=
      database.drop=y
      project.name=Hison
      hibernate.connection.username=root
      hibernate.connection.driver_class=com.mysql.jdbc.Driver
      hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
      project.type=ear
      icefaces.home=
      database.exists=n
      jboss.home=C\:/jboss-5.0.1.GA
      hibernate.dialect=org.hibernate.dialect.MySQLDialect
      hibernate.connection.url=jdbc\:mysql\://192.168.0.2\:3306/hison
      icefaces=n

      Hison-dev-ds.xml:

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE datasources
          PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
          "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
         
      <datasources>  
         <local-tx-datasource>
            <jndi-name>HisonDatasource</jndi-name>
            <connection-url>jdbc:mysql://192.168.0.2:3306/hison</connection-url>
            <driver-class>com.mysql.jdbc.Driver</driver-class>
            <user-name>root</user-name>
            <password>horsens</password>
         </local-tx-datasource>
         
      </datasources>
        • 2. Re: java.sql.SQLException: Access denied for user 'root'@'localhost'
          Nikos Paraskevopoulos Novice

          The server URL is specified as 192.168.0.2. Is this the address of your machine in the local net? Why don't you try giving access to root@192.168.0.2 in mysql? Also try specifying localhost at the server connection string.

          • 3. Re: java.sql.SQLException: Access denied for user 'root'@'localhost'
            Jaime Martin Apprentice

            I usually use Sybase, but I´ve tested recently Seam with MySql and have had no problem to connect. My configuration is like yours and for my test I used localhost instead of a numerical IP as MySql server was there.


            It´s strange that the error says Access denied for user 'root'@'localhost' instead of 'root'@'192.168.0.2' that is what you mean to achieve.
            Check all your configuration files to make sure you have not any localhost references there. It seems it tries to connect to localhost but your database is in IP 192.168.0.2

            • 4. Re: java.sql.SQLException: Access denied for user 'root'@'localhost'
              henrik kristiansen Newbie

              The URL “192.168.0.2” is for localhost.
              I have tried using both “localhost” and “127.0.0.1” as url, but they both failed.  
              I was told on another forum that I should use my PC ip,  because the error could be caused by either using “localhost” or  “127.0.0.1” as URL

              • 5. Re: java.sql.SQLException: Access denied for user 'root'@'localhost'
                henrik kristiansen Newbie
                I fixed this issue by reinstalling my box, but now I'm facing a new problem.
                My entities aren't transformed into tables in the database.

                Here is one of my entities:

                @Entity
                @Table(name="BoatType")
                @Name("BoatType")
                public class BoatType implements Serializable {

                    @Id
                    @GeneratedValue
                    protected long Id;

                    @NotNull
                    @Length(max=250)
                    protected String name;

                    public long getId() {
                        return Id;
                    }

                    public String getName() {
                        return name;
                    }

                    public void setName(String name) {
                        this.name = name;
                    }
                }

                <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                             version="1.0">
                            
                   <persistence-unit name="Hison">
                      <provider>org.hibernate.ejb.HibernatePersistence</provider>
                      <jta-data-source>HisonDatasource</jta-data-source>
                      <!-- The <jar-file> element is necessary if you put the persistence.xml in the WAR and the classes in the JAR -->
                      <!--
                      <jar-file>../../vehicles.jar</jar-file>
                      -->
                      <properties>
                         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                         <property name="hibernate.show_sql" value="true"/>
                         <property name="hibernate.format_sql" value="true"/>
                         <property name="jboss.entity.manager.factory.jndi.name" value="java:/HisonEntityManagerFactory"/>
                      </properties>
                   </persistence-unit>
                   
                </persistence>


                11:43:00,656 INFO  [SchemaExport] Running hbm2ddl schema export
                11:43:00,656 INFO  [SchemaExport] exporting generated schema to database
                11:43:00,656 INFO  [SchemaExport] Executing import script: /import.sql
                11:43:00,656 INFO  [SchemaExport] schema export complete

                after deploying my database is still empty