[2.0] Help wanted getting sample app connected to MySQL

855 views
Skip to first unread message

Dan Cancro

unread,
Oct 16, 2012, 10:36:01 AM10/16/12
to play-fr...@googlegroups.com
Hi group.  I'm brand new here and having some trouble getting started.

I edited build.scala.  It has this

    val appDependencies = Seq(
   "mysql" % "mysql-connector-java" % "5.1.18"
    )
--------------------------------------------------------------------------------

I edited application.conf.  It has this

db.default.url="jdbc:mysql://localhost/computer-database"
db.default.driver=com.mysql.jdbc.Driver
db.default.user=root

--------------------------------------------------------------------------------

Initially, it told me the database needed evolution.  Then I did evolution 1.sql and got this...

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sequence company_seq start with 1000' at line 1 [ERROR:1064, SQLSTATE:42000]

Then it tried to do 2.sql and said...

play.api.db.evolutions.InconsistentDatabase: Database 'default' is in inconsistent state! [An evolution has not been applied properly. Please check the problem and resolve it manually before marking it as resolved.]

Now it's saying...

play.api.db.evolutions.InvalidDatabaseRevision: Database 'default' needs evolution! [An SQL script need to be run on your database.]


Any tips how to fix this?  
Apparently, this is all because MySQL doesn't have sequences.  Should I do something to deal with that?  Should I start over?

Noah Nordrum

unread,
Oct 16, 2012, 11:01:21 AM10/16/12
to play-fr...@googlegroups.com
I don't know exactly how it processes the files, but given that it
says "line 1", I'm assuming you don't have the proper format.

http://www.playframework.org/documentation/2.0/Evolutions

Here's the example from the above link. I would guess you're missing
the --!Ups/--!Downs

-------
# Users schema

# --- !Ups

CREATE TABLE User (
id bigint(20) NOT NULL AUTO_INCREMENT,
email varchar(255) NOT NULL,
password varchar(255) NOT NULL,
fullname varchar(255) NOT NULL,
isAdmin boolean NOT NULL,
PRIMARY KEY (id)
);

# --- !Downs

DROP TABLE User;
> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/OovsuKr9kGUJ.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.

Guillaume Bort

unread,
Oct 16, 2012, 11:46:37 AM10/16/12
to play-fr...@googlegroups.com
But if you try to apply a corrupted evolution (and typically here you
try to apply a script that is not supported by your database), you
have to fix the schema yourself manually and then mark the evolution
as applied.

In dev mode it is often simpler to drop the whole database and start
from scratch (script 1.sql). But in prod mode, if you try to update
your production database with a broken evolution, play freeze
everything and let you fix the database manually.
--
Guillaume Bort, http://guillaume.bort.fr

Dan Cancro

unread,
Oct 16, 2012, 3:04:27 PM10/16/12
to play-fr...@googlegroups.com
Not sure if I'm more confused or less confused.  In my 1.sql of sample app "computer-database-jpa", I only see the creation of the Company and Computer tables, not a User table.

So 

1) I dropped the computer-database schema and made a new one.
2) Then I hit http://localhost:9000/.  It told me that it needed to apply 2.sql.  I thought that odd.  I expected it would see that the database was brand new and want to apply 1.sql
3) I edited 1.sql by removing the sequence lines and adding auto_increment to the ID fields.  I don't know MySQL at all but this seems to be how it does sequences.
4) I restarted play and hit http://localhost:9000/ again.  This time, it told me that the db needed an evolution and displayed 1.sql followed by 2.sql. 
5) I clicked Apply the Script.  It succeeded with 1.sql.  Then it said it needed to do an evolution and displayed 2.sql.
6) I clicked Apply the Script.  Then it said it needed to do an evolution and displayed 2.sql.
7) I clicked Apply the Script.  Then it said it needed to do an evolution and displayed 2.sql.
8) I clicked Apply the Script.  Then it said it needed to do an evolution and displayed 2.sql.
9) I clicked Apply the Script.  Then it said it needed to do an evolution and displayed 2.sql.
etc, etc, etc...

Here's what it says in the console...

! @6c3c0gdea - Internal server error, for request [GET /] ->

play.api.db.evolutions.InvalidDatabaseRevision: Database 'default' needs evolution! [An SQL script need to be run on you
r database.]
        at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:424) ~[play_2.9.1.jar:2.0]
        at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:410) ~[play_2.9.1.jar:2.0]
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) ~[scala-library.jar:0.11.2]
        at scala.collection.immutable.List.foreach(List.scala:45) ~[scala-library.jar:0.11.2]
        at play.api.db.evolutions.EvolutionsPlugin.onStart(Evolutions.scala:410) ~[play_2.9.1.jar:2.0]
        at play.api.Play$$anonfun$start$1.apply(Play.scala:60) ~[play_2.9.1.jar:2.0]
[info] play - database [default] connected at jdbc:mysql://localhost/computer-database
[error] application -

Dan Cancro

unread,
Oct 18, 2012, 5:08:42 PM10/18/12
to play-fr...@googlegroups.com
Today I read a post here that directed me to this page about connecting to a database.  It said to make sure this line is NOT commented in conf/application.conf:
ebean.default="models.*"

I didn't see it in there so I added it to the end.  Then I got a ClassNotFoundException complaining about models.Company.  
So I added "C:\Documents and Settings\Dan\My Documents\myapps\computer-database-jpa\app\models" to my classpath.  Then that error went away and I got the old error message about 2.sql again

I don't know if I have a good database driver.  I googled "MySQL database drivers" and got a page with a bunch of choices.  This one seemed like it might be right.
I downloaded mysql-connector-java-5.1.22.zip.
I didn't know what to do with it.  So I extracted it to my desktop and opened the README file.  It has 999 lines so I gave up and got some ice cream.
Then I discovered another file that might help.  It's called connector-j.html.  I opened it and found a part about installation.
The instructions did not tell me where to put the file, just to put it in my classpath.  
I thought it would make sense to put it in the directory where MySQL was installed.  So I located C:\Program Files\MySQL.  I looked around for something that might be a driver and only found .java files.
The I read in the MySQL docs that 
To use MySQL Connector/J with an application server such as GlassFish, Tomcat or JBoss, read your vendor's documentation for more information on how to configure third-party class libraries
I figure that they are telling me the instructions should be provided by Play in this situation.
In another paragraph it said 
you can put the driver's .jar file in the WEB-INF/lib subdirectory of your webapp
but I didn't see a WEB-INF directory in any of the play stuff.  So I still don't know where I should put the driver file.
I give up and just put it here: C:\Program Files\MySQL\MySQL Server 5.6\lib, and add that to the system classpath.
I press Ctrl-D and then run to restart the app
I get the same NoClassDefFoundError about models.Company

So I am just as stuck as before.

Is this a typical getting started Odyssey?  All I want to do is get the sample app going with MySQL, a super common database.  My failed research process seems pretty undirected and futile for something that I would expect every other person to have to do in the beginning.  Is Play intended for an audience for whom all of these "where do I put this file" and "why is it not finding my class" quandaries obvious?

Łukasz Radziwonowicz

unread,
Apr 3, 2013, 7:58:38 AM4/3/13
to play-fr...@googlegroups.com
I had the same problem. After searching I've found the solution: http://stackoverflow.com/a/15786684/151813

Cheers,
Lukasz
Reply all
Reply to author
Forward
0 new messages