I am using wamp server, it comes with mysql 5.5.16 and I am trying use the mysql from grails 1.3.7. In my Buildconfig.groovy file i have added "runtime 'mysql:mysql-connector-java:5.1.6'" under dependencies and my datasource.groovy looks like this:
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
url = "jdbc:mysql://localhost:3306/moviestore_dev"
}
but when i refresh dependencies or run the app, i get error=>
:: mysql#mysql-connector-java;5.1.6: not found
I can connect to the database but the data in the database remains as long as the app is running, the next time I run the app, all the data are gone !
I have no idea what is happening, please help !
Thanks
problem is in
dbCreate = "create-drop"
use
dbCreate = "update"
• create-drop: Drops and re-creates the database schema on each application load
• create: Creates the database on application load
• update: Creates and/or attempts an update to existing tables on application load
• [blank]: Does nothing
Related
My Grails app uses a h2 database in dev mode (the default behaviour for Grails apps). The DB connection settings in DataSource.groovy are
dataSource {
pooled = true
jmxExport = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
}
I'm trying to setup a connection for this database using IntelliJ IDEA's database client tools. I start off creating the connection like so
Then in the following dialog, I enter the JDBC URL
And choose all available databases on the "Schemas & Tables" tab.
The "Test Connection" button indicates success, but as you can see from the red circle, no tables are found. It seems like I've correctly setup a connection to the h2 server, but not the schema itself.
BTW, I try to setup this connection once the app is running, so I'm sure that the schema/tables do actually exist.
Your configuration is for an h2:mem database. Memory Databases have no tables upon connecting to them, and any & all tables are lost when all the connections are closed. Furthermore, a (named) in memory database is unique to the JVM process that opens it. From the H2 documentation:
Sometimes multiple connections to the same in-memory database are required. In this case, the database URL must include a name. Example: jdbc:h2:mem:db1. Accessing the same database using this URL only works within the same virtual machine and class loader environment. (Emphasis added)
This means IDEA will create a unique devDb in its JVM (and classloader) space and your application will create a unique devDb in its JVM (and classloader) space. You can not connect to an in memory database from an external JVM process.
If you want to connect both your application and IntelliJ IDEA (or any other DB tool) to an H2 database at the same time, you will need to either
use an embedded database (that writes to a file) in your application and use Mixed Mode to allow IntelliJ IDEA (and/or other database tools) to connect to it
use a server mode database
See http://www.h2database.com/html/features.html#connection_modes for more information.
This article has a great write up on how to set up the IntelliJ database client to connect to an H2 in-memory database if you happen to be using Spring Boot: http://web.archive.org/web/20160513065923/http://blog.techdev.de/querying-the-embedded-h2-database-of-a-spring-boot-application/
Basically, you wrap the in-memory database with a tcp server, then you have an access point to connect with a sql client via remote access.
Try to open http://localhost:8080/dbconsole and fill your jdbc url
During development you can use grails h2 dbconsole
Let's imagine you've already created entities (Users, Addresses)
Step 1. In application.yml file add H2 properties.
server:
port: 8080
spring:
datasource:
url: jdbc:h2:~/data/parserpalce (for Mac OS)
username: sa
password: password
driver-class-name: org.h2.Driver
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
h2:
console:
enabled: true
Step 2. Add H2 Database client
Step 3. Configure H2 database client properties based on your application.yml properties.
Step 4. Run the application.
Step 5. Check if tables(Users, Addresses) are created.
Or you can use H2 console for it in browser:
http://localhost:8080/h2-console
P.S. Do not forget to paste appropriate values in fields!
I am writing test cases to verify the response from REST call. I am doing the following:
RestResponse response = rest.get("http://localhost:8080/dynamic-content-services/api/"
But I want to use the in-memory database. I know localhost will not work but what will be the URL in that case?
This is my test environment
test {
dataSource {
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
}
}
you can have a look to this post I wrote. It might help you out:
http://aruizca.com/integrated-vs-functional-testing-how-to-test-rest-apis-in-grails-using-spock/
Look at the functional testing part. The default H2 configuration for test should work out of the box.
Does anyone know if it's possible to autogenerate a database on the as400 / iSeries via the domain classes in a grails application as you can do for other DB's ? I can use existing tables via mappings but i'm trying to create a new app and it won't create new tables for me ..
My datasource ..
dbcreate = "create-drop"
username = "user"
password = "password"
driverClassName = "com.ibm.as400.access.AS400JDBCDriver"
url = "jdbc:as400://xxx.xxx.xxx.xxx;naming=system;libraries=,SAMPLEDB;date format=iso;prompt=false;translate binary=true"
dialect = "org.hibernate.dialect.DB2400Dialect"
But this just throws an error basically saying it can't find the files that i'm writing to via bootstrap .. Anyone know if it's possible ? .. Fwiw i'm on v5r4 of the os/400 OS - and yes I know it's old and not supported anymore ..
Thanks
My situation: I work with a lot of RPG programmers who have created files on the IBM-i in a way that does not create a journal. I've created a Grails app which uses a db2 jdbc driver to connect to a file and update, insert, etc. I'm getting an error:
com.ibm.db2.jdbc.app.DB2DBException: MYFILE in MYLIB not valid for operation.
Cause . . . . . : The reason code is 3 . Reason codes are:
...blah blah blah...
3 -- MYFILE not journaled, no authority to the journal, or the journal state is *STANDBY. Files with an RI constraint action of CASCADE, SET NULL, or SET DEFAULT must be journaled to the same journal.
...blah blah blah...
I know that I could start journaling the file with STRJRNPF, but I'd rather not keep up with it (no scolding please). Is there a parameter for the db2 jdbc connection url that I can set to let it know not to try to commit?
Here's my current connection info:
dataSource
{
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
pooled = true
url = "jdbc:db2:*local;naming=system;libraries=LIBS;errors=full"
driverClassName = "com.ibm.db2.jdbc.app.DB2Driver"
username = "user"
password = "pass"
dialect = org.hibernate.dialect.DB2400Dialect.class
}
EDIT: Here is what I've tried:
url = "jdbc:db2:*local;naming=system;libraries=LIBS;errors=full;transaction isolation=none"
Finally, this did end up having to do with Grails/Hibernate. Here is what the datasource ended up looking like:
dataSource
{
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
pooled = true
url = "jdbc:db2:*local;naming=system;libraries=LIBS;errors=full;transaction isolation=none"
driverClassName = "com.ibm.db2.jdbc.app.DB2Driver"
username = "user"
password = "pass"
dialect = org.hibernate.dialect.DB2400Dialect.class
properties{
defaultTransactionIsolation = 0
}
}
Thanks to #Buck Calabro 's comments and this question.
What do you think "keep up with it" entails? By default, the system will do a lot of journal management for you. Welcome to IBM i. ;-)
I'm trying to have a look at the tables generated in h2 db used in Grails project, but something's amiss.
I connect to the browser console at http://127.0.1.1:8082/ but all that's there to browse is INFORMATION_SCHEMA and Users. How do I get tho the tables used/generated by the app?
Just started building out the app and only few domain classes are in place and I'm trying to get a feel for working h2. Prior to that I've been using PostgreSql in all projects so this is very unnerving for the moment.
Thanks in advance
Are you using the right JDBC URL when logging in?
The default in grails is jdbc:h2:mem:devDB.
When an non-existing URL is given, like jdbc:h2:blabla, an empty database is created, with the default INFORMATION_SCHEMA and Users as you described.
Make sure you connect to the URL where your grails application stores its tables. You can find the URL in $GRAILS_PROJECT/config/DataSource.groovy, after the url definition.
environments {
development {
dataSource {
pooled = false
logSql = false
username = "sa"
password = ""
dialect = "com.hp.opr.hibernate.dialect.H2Dialect"
driverClassName = "org.h2.Driver"
dbCreate = "create-drop"
url = "jdbc:h2:mem:devDB;DB_CLOSE_DELAY=-1;MVCC=TRUE"
}
}
}
If you're using 2.0 the web console is enabled by default in dev mode and can be enabled in other environments: http://grails.org/doc/2.0.0.M2/guide/conf.html#databaseConsole
If you're not using 2.0 yet you can install the http://grails.org/plugin/dbconsole plugin or follow the link to my blog post and set it up yourself if you want to customize the url (or if you're using Grails pre-1.3.6 since the plugin has an artificial version restriction to 1.3.6+)
... so in datasource I changed the url to: url = "jdbc:h2:rswDb" (removing the 'mem' part and changing the name of the db). Then 3 db files showed up in the root dir of the project.
Next, in db console set the jdbc url to: jdbc url: jdbc:h2:~/work/web/rsw/rswDb
... and when I hit 'connect' all the tables were there!
Thanks again!