Java goes SQL: schön wär's

Enumerator

Mitglied Kamel
Abend!

Wie der Titel des Threads erahnen lässt, bekomme ich es einfach nicht hin, mit Java auf eine MySQL Datenbank zuzugreifen.
Ok, bis hierhin langweilig, quasi ein alter Hut. Doch damit würde ich Euch ja nie belästigen: es liegt nicht am Passwort.
Nein, auch nicht an IP, Port oder was-weis-ich. Glaubt's mir einfach.
Die Sache ist ein wenig verzwickt, von daher komme ich erst einmal zum Setup:

- Server 1: Java (1.)5 / Tomcat 5.5
- Server 2: Java (1.)6 / Tomcat 6
- Server 3: MySQL 5.0.67
- Server 4: MySQL 5.0.51
- OS: FreeBSD 6.1

1 und 2 haben identische Konfiguration, ebenso 3 und 4 (soweit das bei unterschiedlichen Software-Versionen und Hardware-Instanzen möglich ist, klar).
Verbindungen nach MySQL auf Server 4 sind problemlos möglich, bei Server 3 erhalte ich nur Fehlermeldungen (siehe unten).
Merkwürdig ist, das nur Java sich nicht verbinden kann. Via Kommandozeile, Perl, C, PHP - alles kein Problem.
Nach stundenlangem Googlen und Probieren komme ich zu dem Schluss: entweder ich bin saudoof, oder das ist ein Bug in einer der Bibliotheken.
Jetzt suche ich dringend jemanden, der eine beiden Optionen einwandfrei bestätigen und begründen kann...

Irgendwelche Ideen?

Greetz
Enum



PS: Fehlermeldung, Backtrace und evtl.relevante SQL-Tabellen (aus Sicherheitsgründen überarbeitet):

Code:
org.hibernate.exception.GenericJDBCException: could not initialize a collection: [com.xXxXx.db.data.Item.itemData#52794]
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.loader.Loader.loadCollection(Loader.java:2001)
        at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
        at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
        at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
        at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
        at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
        at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
        at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
        at org.hibernate.collection.PersistentSet.size(PersistentSet.java:139)
        at com.xXxXx.db.PersistenceManager.searchHotelData(PersistenceManager.java:279)
        at com.xXxXx.ws.searchTask.PartnerSearchTask.searchHotels(PartnerSearchTask.java:69)
        at com.xXxXx.ws.searchTask.RegionSearchTask.processData(RegionSearchTask.java:89)
        at com.xXxXx.ws.searchTask.SearchTask.run(SearchTask.java:36)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLException: Access denied for user 'userVier'@'%' (using password: YES)
        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:3515)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1912)
        at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
        at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
        at org.hibernate.loader.Loader.doQuery(Loader.java:674)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
        at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
Code:
+-----------------+------------+-----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| Host            | User       | Password  | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections |
+-----------------+------------+-----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| localhost       | root       | #         | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                |          |            |             |              |             0 |           0 |               0 |                    0 |
| db1.xXxXxXx.com | root       | #         | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                |          |            |             |              |             0 |           0 |               0 |                    0 |
| 127.0.0.1       | root       | #         | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                |          |            |             |              |             0 |           0 |               0 |                    0 |
| %               | root       | #         | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | N          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                |          |            |             |              |             0 |           0 |               0 |                    0 |
| %               | userEins   | #         | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                |          |            |             |              |             0 |           0 |               0 |                    0 |
| %               | userVier   | #         | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                |          |            |             |              |             0 |           0 |               0 |                    0 |
| 10.2.1.2        | repl       | #         | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | Y               | Y                | N                | N              | N                   | N                  | N                |          |            |             |              |             0 |           0 |               0 |                    0 |
| %               | userZwei   | #         | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                |          |            |             |              |             0 |           0 |               0 |                    0 |
| %               | userDrei   | #         | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                |          |            |             |              |             0 |           0 |               0 |                    0 |
| 10.2.1.3        | repl       | #         | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | Y               | Y                | N                | N              | N                   | N                  | N                |          |            |             |              |             0 |           0 |               0 |                    0 |
| 10.2.1.1        | repl       | #         | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | Y               | Y                | N                | N              | N                   | N                  | N                |          |            |             |              |             0 |           0 |               0 |                    0 |
| 10.2.1.30       | nagios     | #         | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | Y                | N                | N              | N                   | N                  | N                |          |            |             |              |             0 |           0 |               0 |                    0 |
+-----------------+------------+-----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
Code:
+------+---------------------+------------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+
| Host | Db                  | User       | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Create_tmp_table_priv | Lock_tables_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Execute_priv |
+------+---------------------+------------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+
| %    | xXxXxXx             | userEins   | Y           | Y           | Y           | Y           | Y           | Y         | Y          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | Y                  | Y            |
| %    | xXxXxXx             | userVier   | Y           | Y           | Y           | Y           | Y           | Y         | N          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | Y                  | Y            |
| %    | test                | userEins   | Y           | Y           | Y           | Y           | Y           | Y         | Y          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | Y                  | Y            |
| %    | xXxXxXx\_archiv     | userVier   | Y           | Y           | Y           | Y           | Y           | Y         | N          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | Y                  | Y            |
| %    | xXxXxXx\_archiv     | userEins   | Y           | Y           | Y           | Y           | Y           | Y         | Y          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | Y                  | Y            |
| %    | information\_schema | userEins   | Y           | Y           | Y           | Y           | Y           | Y         | Y          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | Y                  | Y            |
| %    | innodb              | userEins   | Y           | Y           | Y           | Y           | Y           | Y         | Y          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | Y                  | Y            |
| %    | innodblogs          | userEins   | Y           | Y           | Y           | Y           | Y           | Y         | Y          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | Y                  | Y            |
| %    | mysql               | user       | Y           | Y           | Y           | Y           | Y           | Y         | Y          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | Y                  | Y            |
| %    | xXxXxXx\_archiv     | userZwei   | Y           | N           | N           | N           | N           | N         | N          | N               | N          | N          | N                     | N                | N                | N              | N                   | N                  | N            |
| %    | xXxXxXx             | userZwei   | Y           | N           | N           | N           | N           | N         | N          | N               | N          | N          | N                     | N                | N                | N              | N                   | N                  | N            |
| %    | xXxXxXx             | userDrei   | Y           | N           | N           | N           | N           | N         | N          | N               | N          | N          | N                     | N                | N                | N              | N                   | N                  | N            |
| %    | xXxXxXx\_archiv     | userDrei   | Y           | N           | N           | N           | N           | N         | N          | N               | N          | N          | N                     | N                | N                | N              | N                   | N                  | N            |
+------+---------------------+------------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+
 
Zuletzt bearbeitet:
Additionals...

Merkwürdiger weise sagen mir diverse Monitoring-Tools, die Server wären verbunden. Quasi als ob ich mich zwar Connecten könnte, aber keine Zugriffsrechte auf die Datenbank hätte... Aber die hab ich doch, grml.
 
es liegt nicht am Passwort.
Nein, auch nicht an IP, Port oder was-weis-ich. Glaubt's mir einfach.

nun ja.....
also:

Code:
Caused by: java.sql.SQLException: Access denied for user 'userVier'@'%'

und:

Code:
| %               | userVier   | #         | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                |          |            |             |              |             0 |           0 |               0 |                    0 |

also, keine Ahnung...aber wie es ausschaut hat userVier hat irgendwie keinerlei Rechte....(ich steck in MySQL jetzt nicht soooo drin)

komme ich zu dem Schluss: entweder ich bin saudoof, oder das ist ein Bug in einer der Bibliotheken.
naja...
(bei mir war es letztendlich doch *meist* ein Fehler von mir...)
 
Sorry, aber das scheint nicht das Problem zu sein.
Es ist richtig das userVier keine rechte hat - laut der Tabelle `mysql`.`user`. Die bezieht sich global auf alle Datenbanken. In der Tabelle `mysql`.`db` wird allerdings Vollzugriff gewährt - auf die Datenbank `xXxXxXx`.
Du hast schon recht, "Access denied" scheint ziemlich eindeutig. Nur bin ich mir verdammt sicher dass ich das richtige Passwort angegeben habe. Im Übrigen habe ich das mit den Rechten auf einem weiteren System getestet - selbe Konfiguration wie hier bei "userVier". Funktioniert einwandfrei. Natürlich nur wieder mit allem was nicht nach Kaffee riecht. :rolleyes:
Ausserdem kann ich mich ja wie gesagt auf den Server mit MySQL 5.0.51 ohne Probleme connecten - und der hat das gleiche Setup. Ich hab's nicht nur geprüft, ich hab's auch schon zigmal auf andere Usernamen und Passwörter umgestellt...
 
Das mit den Monitoring-Tools ziehe ich zurück. Bedienfehler. Dummheit. Was auch immer. Dennoch besteht das eigentliche Problem.
Hier scheinen inzwischen alle Betriebsblind zu sein - keiner kann sich einen Reim darauf machen. Die geilste Idee kam vom Praktikanten: Encoding-Probleme in den Configs der Applikation oder beim Übertragen des PWs...:suspekt:

Greetz
 
Ich hab schon Pferde kotzen gesehen....
Lol, das Vergnügen hatte ich noch nicht.

Vergiss den Code. Wir verwenden in Java ausschließlich Hibernate, aktuell in Version 3. jdbc, mysql, c3p0 - das war's. Und ich kann nur immer wieder betonen: es geht! Nur auf diesem einen (MySQL) Server nicht...

Aber schon mal Danke für Dein bemühen... ;-]
 
Tja, wie gesagt es könnte auch an der ConnectionURL (die musst du in der Hibernate.cfg.xml angeben) oder den Treiber liegen.
Gerade bei MySQL 5 brauchst du nen anderen Treiber als für die vorherigen Versionen.
Welchen Treiber nutzt du denn?
 
treiber: mysql-connector...
5.1.7 auf dem tomcat 6
3.1.13 auf dem tomcat 5.5

die hibernate.cfg.xml sieht einwandfrei aus - kannst ja mal gucken ;-)

Code:
<!DOCTYPE hibernate-configuration PUBLIC 
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
 <session-factory>
  <property name="connection.datasource">java:comp/env/jdbc/xXxXxXx</property>
  <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="connection.url">jdbc:mysql://10.2.1.1:3306/xXxXxXx</property>
  <property name="connection.username">xXxXxXx</property>
  <property name="connection.password">#</property>
  <property name="hibernate.c3p0.min_size">2</property>
  <property name="hibernate.c3p0.max_size">5</property>
  <property name="hibernate.c3p0.timeout">1800</property>
  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
  <property name="cache.use_query_cache">false</property>
  <property name="cache.use_minimal_puts">false</property>
  <property name="max_fetch_depth">3</property>
  <property name="show_sql">false</property>
  <property name="format_sql">true</property>
  <property name="hbm2ddl.auto">none</property>
  <property name="current_session_context_class">thread</property>
  <mapping resource="org/MyClass.hbm.xml"/>
  <mapping class="com.xXxXxXx.db.data.Item"/>
  <mapping class="com.xXxXxXx.db.data.Path"/>
  <!-- einige mappings entfernt -->
  <class-cache class="com.xXxXxXx.db.data.Path" usage="read-only" />
  <class-cache class="com.xXxXxXx.db.data.PathName" usage="read-only" />
  <collection-cache collection="com.xXxXxXx.db.data.Path.pathNames" usage="read-only"/>
  <class-cache class="com.xXxXxXx.db.data.CategoryData" usage="read-only" />
  <class-cache class="com.xXxXxXx.db.data.Item" usage="read-only" />
  <collection-cache collection="com.xXxXxXx.db.data.Item.itemStatistics" usage="read-only"/>
  <collection-cache collection="com.xXxXxXx.db.data.Item.itemDescriptions" usage="read-only"/>
  <collection-cache collection="com.xXxXxXx.db.data.Item.itemPartners" usage="read-only"/>
  <collection-cache collection="com.xXxXxXx.db.data.Item.itemData" usage="read-only"/>
</session-factory>
</hibernate-configuration>
 
Zurück