Connect to MYSQL in Spring Roo

First you need to install MYSQL, then setup the database e.g “jarvis”

then run the following command

jpa setup –provider HIBERNATE –database mysql

then you need to edit the file at src/main/resources/meta-inf/spring/database.properties as follows

#Updated at Sat Sep 15 19:31:58 EST 2012
#Sat Sep 15 19:31:58 EST 2012
database.driverClassName=com.mysql.jdbc.Driver
database.url=jdbc\:mysql\://localhost\:3306/jarvis
database.username=root
database.password=basser

properties list –name database.properties –path String_config_root

this command shows you the configuration.

After you have done this, you can add in the entities

and then do the mvc setup:

web mvc setup

web mvc all –package ~.web

Now if you run the project, it will give the error that the driver is not found

you have to run “perform eclipse” command,

this is a magic command that it will look at the dependencies from the .pom file and download all the libraries(jars) that are required,

it will store the libraries at the local repository, in my case it’s at “C:\Users\Jackie\.m2\repository\”

Remember don’t stop the perform eclipse half way like I did, or you will have to delete the files and do the command again, it took me ages to figure it out why the files are there but it just doesn’t work.

in the persistence.xml, there is a <property name=”hibernate.hbm2ddl.auto” value=”create”/>, this decides what will happen to the table each time you run it.

Advertisements

2 thoughts on “Connect to MYSQL in Spring Roo

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s