Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eclipse an MySQL

 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Eclipse 3.4.2 and MySQL 5.1.26 with the JDBC driver mysql-connector-java-5.1.6.jar. I configured a driver for a MySQL database within Eclipse as follows:

Connection URL: jdbc:mysql://localhost:3306/
Database name: somedb
Driver class: com.mysql.jdbc.Driver
Password: somepassword
User id: someuser

Then in the Data Source Explorer window I configured a datasource using the above driver and:

Database: somedb
URL: jdbc:mysql://localhost:3306/
User name: someuser
Password: somepassword

Testing the connection results in a successful ping. Changing any of the properties to an invalid value results in a ping failure, so I know I am not getting a false positive and that Eclipse really can connect to the database. In addition, I can see the connections in MySQL Administrator.

But, in the Data Source Explorer, when I expand the datasource using "somedb > schemas > somedb > tables", there are no tables showing, yet the database does have tables.

By the way, I have tried the URLs both with (e.g., jdbc:mysql://localhost:3306/somedb) and without (e.g., jdbc:mysql://localhost:3306/) the database name, in both the driver and datasource definitions; a post I found on another site recommended not placing the database name in the driver URL, but that was for Eclipse 3.3 and 5.0.6 MySQL connector.

Does anybody know how to get MySQL properly configured in Eclipse? Actually, I would ignore this (my app works fine), but I have some JPA entity beans and the red underlines are driving me batty.



 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting. I can get rid of the JPA-related errors by closing the database connection. Works for me. But it would still be nice to know how to set up a MySQL connection properly.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
False alarm. It turns out that when I created the database and user, my grant statement was wrong. I did this:

GRANT ALL PRIVILEGES ON somedb TO 'someuser'@'localhost' IDENTIFIED BY 'somepassword' WITH GRANT OPTION;

when I should have done this:

GRANT ALL PRIVILEGES ON somedb.* TO 'someuser'@'localhost' IDENTIFIED BY 'somepassword' WITH GRANT OPTION;

With this change, I can see the tables in Eclipse.

That's what happens when I decide to type the command in by hand rather than use the SQL text file that I already have set up for doing this kind of thing. Sigh.


 
M sallu
Ranch Hand
Posts: 42
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic